我想用shell脚本linux在文件中写一行

我想用shell脚本linux在文件中写一行,linux,shell,file-io,Linux,Shell,File Io,我有一些输入,比如“somespacehere.file somemorespace”sample.cpp“”。 上面这一行我想用shell脚本写在一个文件中。 我应该如何编写shell脚本? 请帮帮我。 谢谢 我写一个代码作为 #!/bin/bash filename= "./xyz.txt" file = open(filename,'w') echo " .file \"sample.cpp\"" > file file .close() 它给了我一个错误 语法错误:“(”

我有一些输入,比如“somespacehere.file somemorespace”sample.cpp“”。 上面这一行我想用shell脚本写在一个文件中。 我应该如何编写shell脚本? 请帮帮我。 谢谢

我写一个代码作为

#!/bin/bash
filename= "./xyz.txt"
file = open(filename,'w')
echo "  .file    \"sample.cpp\"" > file
file .close()
它给了我一个错误

语法错误:“(”意外
最后一行。

以一个shebang和一个echo开头,将您想要的行回送到一个文件?例如

#!/bin/bash

filename="./xyz.txt"
echo "  .file    \"sample.cpp\"" > $filename

不清楚您在这里要问什么。是否要将多个命令连接到一行中?是否要将一个命令的输出作为参数传递给另一个命令?我只想将字符串startshere somespace.file somemorespace“sample.cpp”stringendshere已写入一个文件。您将希望转义这些内部引号。谢谢Kevin,感谢您的反馈,我已使用转义内部引号更新了答案。