user2727195 user2727195 - 1 year ago 100
Linux Question

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 " + path + " && du -hs"
    using ampersand

how can we chain these commands together to form one single command so that
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
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.

Answer Source

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 :

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download