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)
Advertisement
Answer
Please try redirecting stderr to stdout like:
#!/bin/bash opt=$(svcrack -v -u100 -r1-9999 -z3 10.0.0.1 2>&1) echo "myout output $opt"
Here you can read more about command substition.