bash - How to echo "some text" and result of function in one line? - Ask Ubuntu


i'm starting learn bash scripting. , had question. code below working fine,

echo "here current directory: " pwd 

but if want have result of pwd written in same line explanation string? how it? thanks.

you can use command substitution

echo "here current directory: $(pwd)" 

however might want habit of preferring printf on echo

printf 'here current directory: %s\n' "$(pwd)" 

note: tell echo not include terminating newline e.g.

echo -n "here current directory: " pwd 

but it's not recommended - see why printf better echo?


Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User