i want to know how can we get command output to variable in bash
here is my code
#!/bin/bash
opt="svcrack -v -u100 -r1-9999 -z3 10.0.0.1"
opt2="$($opt)"
echo "myout output $opt2"
output
myout output
not working inside function :(
function zwork(){
opt=$(svcrack -v -u100 -r1-9999 -z3 10.0.0.1 2>&1)
echo "myout output $opt"
}
out=$(zwork)
opt, or use thesvcrackcommand directly in the command substitution as in the accepted answer. See I'm trying to put a command in a variable, but the complex cases always fail!.zwork(){ ... }instead offunction zwork(){ ... }