jason
jason

Reputation: 4801

Is there a way to 'inject' a command line output into another command?

for ex :

grep -R "requests" /some/really/long/path/to/type/out

I would like to do something like this

grep -R "requests" (pwd)

Basically, using the output of pwd sorta like a pipe (pipe dosent do it).

Upvotes: 0

Views: 718

Answers (2)

Biber
Biber

Reputation: 727

In bash you can use backtics for this:

grep -R "requests" `pwd`

pwd will be executed and the stdout of pwd will be used as the third parameter of the grep command

Upvotes: 1

choroba
choroba

Reputation: 241898

Use command substitution:

grep -R "requests" $(pwd)

The output of the command in $(...) is used as an argument list to the command. If you want the output to be treated as one word, wrap it in double quotes:

ls "$( command-that-produces-dirname-containing-whitespace )"

Upvotes: 4

Related Questions