0

I need to concatenate a string into a file through a command that is a single valued argument to a script:

defining sample text: TEXT="sample text"

defining characteristic script : transfer.sh $1

desired usage (to be corrected): ./transfer.sh "echo $TEXT >> test.log"

desired output in test.log ... (previous contents) sample text

4

1 回答 1

1

您可以在文件中使用eval命令:transfer.sh

eval $1

它将test.log在最后一行生成“示例文本”。请注意,您传递给transfer.sh脚本的任何内容都将被执行。因此,如果您的用户通过"rm -r /home/alan/papers",您papers文件夹中的所有内容都将被删除。

于 2012-08-29T21:49:19.547 回答