I am wondering if it is possible in BASH to use commands in this way:
lets take command pwd
Lets say I would like to have a variable comm="pwd" and then use it somewhere in program, but when I use it, I get the real pwd command output. Is this even possible?
It's pretty simple, you can just do:
comm='pwd'
# just execute
$comm
# fetch output into variable
output=$($comm)
Try doing this :
var=$(pwd)
The backquote (`) is used in the old-style command substitution, e.g.
foo=`command`
The
foo=$(command)
syntax is recommended instead. Backslash handling inside $() is less surprising, and $() is easier to nest. See http://mywiki.wooledge.org/BashFAQ/082
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With