command substitution: ignored null byte in input がよく分からないです.
Linux でいまログインしているのが tty* なのかそれとも sshd なのかを判定して,その結果に応じて実行コマンドを変更するスクリプト
1 2 3 4 5 |
if [ -f /proc/$PPID/cmdline ]; then if [ "$(command cut -d : -f1 < "/proc/$PPID/cmdline")" != "sshd" ] && [[ $- == *i* ]]; then echo "Hello!" fi fi |
を実行したところ,警告として,
1 |
command substitution: ignored null byte in input |
が出力されました.
この警告,どうも Bash ver. 4.4 からのものらしく,書かれている通り,input された null byte を無視したとのもののよう.対策は,
1 2 3 4 5 |
if [ -f /proc/$PPID/cmdline ]; then if [ "$(command cut -d : -f1 < "/proc/$PPID/cmdline"|tr -d "\0")" != "sshd" ] && [[ $- == *i* ]]; then echo "Hello!" fi fi |
のように tr で NULL を削除すれば良いだけのよう.bash では null 文字の代入ができないということみたいですね.
以上!