Reputation: 55
I am trying to execute a script and store the output of it in a variable rather than displaying it on stdout. My problem is the script I am using I cannot change and it uses stty so no matter what I try I always get the error:
stty: standard input: Inappropriate ioctl for device
My code looks like:
req="script $ip"
response=$($req)
echo $response
I am echoing the request to stdout at the end because I want the user to see it but I also need part of it to be processed in my script.
The script is working as intended it just annoys me that the error message is always displayed to the user.
I have tried adding:
response=$($req "&>/dev/null)
and
response=$($req) &>/dev/null
but no luck and the error message still displays.
I basically just want to hide it from the user.
Upvotes: 2
Views: 463
Reputation: 5305
eval
can help you, but it is insecure.
Use the following method (an eval
alternative):
cmd=(script "$ip")
response=$("${cmd[@]}" 2>/dev/null)
echo "$cmd"
Upvotes: 5