関数の補完をファイルに出力したいと思います。 Iは、上記指示に基づいて、その命令に続くされるコマンドのprintf「%のQ」、bashでprintf "%q"を使うには?
# man printf
%q ARGUMENT is printed in a format that can be reused as shell input, escaping non-print‐
able characters with the proposed POSIX $'' syntax.
を言われた、私は、次のコードを試みました。
#!/bin/bash
# file name : print_out_function_augs.sh
output_file='output.txt'
function print_augs() {
printf "%q " "[email protected]" >> "${output_file}"
echo >> "${output_file}"
}
print_augs a 'b c'
cat "${output_file}"
rm "${output_file}"
及び結果は以下の通りである
bash print_out_function_augs.sh
を実行し、
a b\ c
Iはprint_augs機能元のオーグメントある
a 'b c'
ような結果を期待。
出力と元の機能が異なるのはなぜですか? オリジナルのオーグメントをそのまま印刷することはできますか?
ありがとうございました。心の中で
は、詳細な説明と解決策をありがとうございました。私は 'b \ c'で '\'を想像することができませんでした。エスケープ文字です。 – mora