2017-06-19 89 views
0

我在我的mac控制台上创建了一个.sh文件。Mac Osx使用sh将文本插入创建的文件

myshfile.sh 

从我sh文件里面我已经创建了一个文件:

所以:

touch index.js 

所以在整个我这运行它:

sh myshfile.sh 

我的问题是。如何在index.js中插入一些文本,例如:

console.log('hello from index.js'); 

...对于sh命令?

回答

1

使用>>重定向追加或只是>如果你想覆盖文件的以前的内容。

$ touch index.js 
$ echo "console.log('hello from index.js');" >> index.js 
$ cat index.js 
console.log('hello from index.js'); 
+0

'touch'命令不需要;当shell用'>>'打开时,'index.js'将在需要时创建。 – chepner