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

nvidia - NV18 [GeForce4 MX 4000] driver - Ask Ubuntu

drivers - No wi-fi network after install - Ask Ubuntu