这可能是许多常见问题解答 - 而不是使用:
cat file | command
Run Code Online (Sandbox Code Playgroud)
(这被称为无用的猫),正确的方式应该是:
command < file
Run Code Online (Sandbox Code Playgroud)
在第二,"正确"的方式 - 操作系统不必产生额外的过程.
尽管知道这一点,我继续使用无用的猫有两个原因.
更美观 - 我喜欢数据仅从左到右均匀移动.而且它更容易更换cat别的东西(gzcat,echo,...),添加第二个文件或插入新的过滤器(pv,mbuffer,grep...).
我"觉得"在某些情况下可能会更快.更快,因为有2个进程,1st(cat)执行读取而第二个执行任何操作.它们可以并行运行,这意味着有时可以更快地执行.
我的逻辑是否正确(第二个原因)?
TL; DR; 什么是shell脚本?它是一种编程语言/我们在shell脚本中使用的编程语言是什么?
免责声明:有点offtopic
所以bash代表Bourne-again shell.(Unix)Shell是一个命令行用户界面,或者可以称之为解释器(?)
所以我正在填写一份新工作的应用程序,你会被要求获得不同编程语言的经验,然后在底层有其他经验 - 我开始输入python 2.7,powershell,bas ...等等!bash不是一种编程语言 - 它是一个可以执行shell脚本的控制台...所以......呃......天哪,我不知道!
我正在Mac上制作NW.js应用程序,并希望通过双击图标以开发模式运行应用程序.第一步,我正在尝试使我的shell脚本工作.
在Windows上使用VSCode(我想获得时间),我run-nw在项目的根目录创建了一个文件,其中包含:
#!/bin/bash
cd "src"
npm install
cd ..
./tools/nwjs-sdk-v0.17.3-osx-x64/nwjs.app/Contents/MacOS/nwjs "src" &
Run Code Online (Sandbox Code Playgroud)
但我得到这个输出:
$ sh ./run-nw
: command not found
: No such file or directory
: command not found
: No such file or directory
Usage: npm <command>
where <command> is one of: (snip commands list)
(snip npm help)
npm@3.10.3 /usr/local/lib/node_modules/npm
: command not found
: No such file or directory
: command not found
Run Code Online (Sandbox Code Playgroud)
我真的不明白:
\r\n用\n(以防\r造成了问题),但它改变不了什么.dirname指令),或者它可能不知道cd …我有这样一个文件:
one
two
three
four
Run Code Online (Sandbox Code Playgroud)
我想在bash脚本中使用for循环来扫描文件行以获取行.以前我用过cut但是我无法给cut命令换行分隔符,我该怎么办?
这样它不起作用:
cut -d'\n' -f1
Run Code Online (Sandbox Code Playgroud)
有什么建议吗?