我正在我的 Mac 控制台上创建一个 .sh 文件。
myshfile.sh
从我的 .sh 文件中创建了一个文件:
所以:
touch index.js
所以总的来说,我这样做是为了运行它:
sh myshfile.sh
我的问题是。如何在 index.js 中插入一些文本,例如:
console.log('hello from index.js');
...用于 sh 命令?
最佳答案
如果您想覆盖文件以前的内容,请使用 >> 重定向来追加或仅使用 >。
$ touch index.js
$ echo "console.log('hello from index.js');" >> index.js
$ cat index.js
console.log('hello from index.js');
关于javascript - Mac OSx 使用 sh 将文本插入到创建的文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44631087/