使用来自文本文件的输入参数来运行控制台应用程序的命令行是什么?
text_file:
This is a simple text file with characters and other
symbols including tabs and new lines
控制台应该得到
$./myapp "This is a simple text file with characters and other symbols including tabs and new lines"
答案1
使用$()
(命令替换)。使用双引号将所有文本作为单个参数传递:
./myapp "$(cat text_file)"
或者,使用带有反引号的旧形式` `
:
./myapp "`cat text_file`"
您可以运行不使用引号的命令来让 shell 拆分和扩展(如果存在通配符)文本:
./myapp $(cat text_file)
./myapp `cat text_file`