cobonzuの日記: bashでの文字列操作 3
また忘れるといけないのでここへ。
文字列の最後の一文字を取得する
STRING=abcdefg
echo ${STRING: -1}
g
最後の一文字を削除する
echo ${STRING/%?/}
abcdef
前者はコロンの後にスペースが必要ということにしばらく気づかなかったよ orz
http://www.softpanorama.org/Scripting/Shellorama/Reference/string_operations_in_shell.shtml
To use negative offsets that begin with a minus sign, separate\
the minus sign and the colon with a space.