Passing line-feed(LF)/new-line character as an argument in bash
本问题已经有最佳答案,请猛点这里访问。
如何在包含lf字符的bash cli中传递参数?比如:
bar
我试过这个:
1 2 3 4 | myprog `printf 'foo bar'` myprog foo bar |
我使用这个bash程序来测试结果:
1 2 | #myprog echo $* |
以及node.js程序
1 2 | #!/usr/bin/env node console.log(process.argv[2]) |
它不起作用。
在
1 2 | myProgram $'foo bar' |
您可以看到形成的字符串的
1 2 3 4 5 6 | $ hexdump -c <<< $'foo bar' 0000000 f o o b a r 0000008 |
以下转义序列也受支持,在这里更新列表,因为它在重复的序列中不可用。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | +-------------+----------------------------------------------------------------------------------------------------------------------------------+ | code | meaning | | | | +-------------+----------------------------------------------------------------------------------------------------------------------------------+ | " | double-quote | | \' | single-quote | | \\ | backslash | | \a | terminal alert character (bell) | | \b | backspace | | \e | escape (ASCII 033) | | \E | escape (ASCII 033) \E is non-standard | | \f | form feed | | | newline | | | carriage return | | \t | horizontal tab | | \v | vertical tab | | \cx | a control-x character, for example, $'\cZ' to print the control sequence composed of Ctrl-Z (^Z) | | \uXXXX | Interprets XXXX as a hexadecimal number and prints the corresponding character from the character set (4 digits) (Bash 4.2-alpha)| | \UXXXXXXXX | Interprets XXXX as a hexadecimal number and prints the corresponding character from the character set (8 digits) (Bash 4.2-alpha)| | nn | the eight-bit character whose value is the octal value nnn (one to three digits) | | \xHH | the eight-bit character whose value is the hexadecimal value HH (one or two hex digits) | +-------------+----------------------------------------------------------------------------------------------------------------------------------+ |