basickarl
basickarl

Reputation: 40454

One liner echo using $(...)

I can get the following to work:

self=$(readlink -f "${BASH_SOURCE[0]}")
echo "Sourcing $self"

But not the following (I want a one liner):

echo "Sourcing $(readlink -f \"${BASH_SOURCE[0]}\")"

Upvotes: 0

Views: 45

Answers (2)

Diego Torres Milano
Diego Torres Milano

Reputation: 69198

You could also use

echo 'Sourcing' $(readlink -f "${BASH_SOURCE[0]}")

Upvotes: 0

chepner
chepner

Reputation: 531055

Command substitution starts a new quoting context, so the quotes in the readlink command are not nested in the quotes surrounding the argument to echo. You don't need to escape them.

echo "Sourcing $(readlink -f "${BASH_SOURCE[0]}")"

Upvotes: 1

Related Questions