简体   繁体   English

终端上的命令行管道语法

[英]command line pipe syntax on terminal

I'm executing following commands in a nodejs application using child processes. 我正在使用子进程在nodejs应用程序中执行以下命令。

  1. which zip to get path of the zip executable which zip zip文件获取zip可执行文件的路径
  2. path-to-zip + " -r abc.zip " + path + " && du -hs abc.zip" using ampersand && path-to-zip + " -r abc.zip " + path + " && du -hs abc.zip"使用&符&&

how can we chain these commands together to form one single command so that path-to-zip gets substituted from 1) which zip . 我们如何将这些命令链接在一起以形成一个命令,以便从1) which zip替换path-to-zip

I'm using which zip to ensure path is correct, tell me if it's useless if the path /usr/bin/zip has been the same and going to be the same across linux and mac os, if that's the case then I'm better off with hardcoding the path in my application, please advise. 我正在使用which zip来确保路径正确,请告诉我/usr/bin/zip路径是否相同并且在Linux和Mac OS上是否相同,如果是的话,那么我最好在我的应用程序中对路径进行硬编码,请告知。

It depends on your shell. 这取决于您的外壳。

Bash is the the most common shell in Linux distribution. Bash是Linux发行版中最常见的shell。

For Bash , there are two common ways which are called Command Substitution to achieve this. 对于Bash ,有两种常见的方法称为Command Substitution命令替代)来实现这一目标。

  1. `which zip` + whatever you want (`means`, I type `due to the syntax policy of StackOverflow.) `which zip` + whatever you want (` means`,由于StackOverflow的语法策略,我键入`。)

  2. $(which zip) + whatever you want

Manual of Command Substitution : 指令替换手册

https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM