简体   繁体   中英

command line pipe syntax on terminal

I'm executing following commands in a nodejs application using child processes.

  1. which zip to get path of the zip executable
  2. path-to-zip + " -r abc.zip " + path + " && du -hs abc.zip" using ampersand &&

how can we chain these commands together to form one single command so that path-to-zip gets substituted from 1) which 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.

It depends on your shell.

Bash is the the most common shell in Linux distribution.

For Bash , there are two common ways which are called Command Substitution to achieve this.

  1. `which zip` + whatever you want (`means`, I type `due to the syntax policy of StackOverflow.)

  2. $(which zip) + whatever you want

Manual of Command Substitution :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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