シェルで文字列から空白を削除する
code:shell
echo "sunny peace" | tr -d ' '
# sunnypeace
shellすぐ忘れるのでメモ。ファイル名に空白を入れたくなくてとりあえず削除するケースとかで使った。
読み出しではIFSも使えるのでいい感じに使い分ける。
trコマンドの他のオプション。
code:shell
echo "sunny peace" | tr ' ' '_'
# sunny_peace
echo "sunny peace" | tr -s ' '
# sunny peace
echo "sunny peace" | tr -s ' ' '_'
# sunny_peace