Nicolas Zozol
Nicolas Zozol

Reputation: 7048

How to concat pipe result with next command?

I would like to run something like :

pwd | echo "++++ working at : $x" 

and the $x variable would show the current directory. I've tried a kind of $(...) stuff with no success.

It has to be in one line to be run in a Dockerfile

Upvotes: 0

Views: 82

Answers (3)

anubhava
anubhava

Reputation: 786031

BASH gives you an env variable called PWD denoting current working directory hence there is no need to call any external utility just use:

echo "++++ working at : $PWD"

Upvotes: 3

alamar
alamar

Reputation: 19343

backticks to the rescue!

echo "++++ working at : " `pwd`

backticks mean: put the command output right here in the command line as argument(s)

Upvotes: 1

123
123

Reputation: 11236

could use xargs

pwd | xargs -I{} echo "++++ working at : {}"

Alternatively you could just not use a pipe and use a subshell

echo "++++ working at : $(pwd)"

Upvotes: 2

Related Questions