How to echo "some text" and result of function in one line?
I'm starting to learn Bash scripting. And I had a question. The code below is working fine,
Echo "Here is your current directory: "
pwdbut 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
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: "
pwdbut it's not recommended - see Why is printf better than echo?
1