Kannan Ekanath
Kannan Ekanath

Reputation: 17601

Piping a command directly to the shell executable

I am trying to understand the difference between the following

Approach 1:

  1. Launch a bash shell
  2. On the bash shell type a command my_command myargs

Approach 2:

  1. Launch a bash shell
  2. Execute the following directly my_command myargs | /bin/bash/

My command passes in approach 1 but does not in approach 2. I was thinking both approaches were equivalent. Of course in approach 1 I have not done any commands/changed the path variables before doing my_command. In approach 2 I am just creating a brand new shell and piping my command into it.

Can someone explain the difference? Is it missing $PATH, environment variables etc? If so how can I echo/find out?

Upvotes: 1

Views: 6919

Answers (1)

SLaks
SLaks

Reputation: 887469

Your "approach 2" pipes the output of my_command to bash.
It's equivalent to

$(my_command myargs)

If you instead pipe the literal text, it will work:

echo my_command myargs | /bin/bash/

Upvotes: 3

Related Questions