【发布时间】:2014-06-19 20:01:10
【问题描述】:
我在 bash 中有一个变量,类似于
filenames='file 1
file 2
file 3'
我需要将上述变量内容中的每一行作为单个参数发送给程序。但我不能对此感到震惊。这是我尝试过的:
python -c 'import sys; print sys.argv' $filenames
['-c', 'file', '1', 'file', '2', 'file', '3']
或
python -c 'import sys; print sys.argv' "$filenames"
['-c', 'file 1\nfile 2\nfile 3']
我期待的是这样的
['-c', 'file 1', 'file 2', 'file 3']
我也尝试过调整IFS 设置,但无法正确设置。对此有何想法?
【问题讨论】:
标签: bash shell command-line-arguments