Bashで文字列の長さを調べるサンプル

2021年12月3日

書式

文字列の長さを調べるには下記のようにします。

$[#string_variable_name}
$[#文字列の変数名]

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#!/bin/bash
#Bash program to find the length of a string
target="Welcome to arkgame.com"
length=${#target}
echo "文字列 '$target' の長さ $length"
#!/bin/bash #Bash program to find the length of a string target="Welcome to arkgame.com" length=${#target} echo "文字列 '$target' の長さ $length"
#!/bin/bash  
#Bash program to find the length of a string  

target="Welcome to arkgame.com"  
length=${#target}  

echo "文字列 '$target' の長さ $length"

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sh test02.sh
文字列 'Welcome to arkgame.com' の長さ 22
# sh test02.sh 文字列 'Welcome to arkgame.com' の長さ 22
# sh test02.sh
文字列 'Welcome to arkgame.com' の長さ 22

 

batch

Posted by arkgame