I'm starting to learn Bash scripting. And I had a question. The code below is working fine,

Echo "Here is your current directory: "

but what if I want to have the result of pwd to be written in the same line as explanation string? How to do it? Thanks.

1 Answer 1


You can use a command substitution

echo "Here is your current directory: $(pwd)"

However you might want to get into the habit of preferring printf over echo

printf 'Here is your current directory: %s\n' "$(pwd)"

Note: you could just tell echo not to include the terminating newline e.g.

echo -n "Here is your current directory: "

but it's not recommended - see Why is printf better than echo?

  • Nice and complete answer, I have nothing to add except an upvote :)
    – Byte Commander
    Oct 27, 2016 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.