【问题标题】:Mac Osx insert text into a created file using shMac Osx 使用 sh 将文本插入到创建的文件中
【发布时间】:2017-06-19 12:50:15
【问题描述】:

我正在我的 mac 控制台上创建一个 .sh 文件。

myshfile.sh

从我的 .sh 文件中,我创建了一个文件:

所以:

touch index.js

所以总的来说,我这样做是为了运行它:

sh myshfile.sh

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

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

...对于 sh 命令?

【问题讨论】:

    标签: javascript node.js macos console sh


    【解决方案1】:

    如果要覆盖文件的先前内容,请使用 >> 重定向来追加或仅使用 >。

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

    【讨论】:

    • touch 命令不再是必需的; index.js 将在 shell 使用 >> 打开时在必要时创建。
    猜你喜欢
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    • 2021-08-10
    • 1970-01-01
    • 2012-06-25
    • 2016-07-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多