1

I am trying to hide the output of this command:

string=$(su - user -c "ssh $L_NAME 'cat ~/.ssh/known_hosts'")

I've tried to do:

string=$(su - user -c "ssh $L_NAME 'cat ~/.ssh/known_hosts'") &> /dev/null

but it doesn't work. Does anyone know how to hide the output of the ssh command in this case?

Thanks

11
  • the assignment itself doesn't have output. It's coming from the subcommand, what do you expect the value of string when you null the output? Commented Apr 19, 2016 at 17:50
  • yes, i would expect it to be null. however, when i run the script it shows the ssh output Commented Apr 19, 2016 at 17:57
  • move the redirect into the parenthesis then. Commented Apr 19, 2016 at 17:58
  • 1
    What is the output you want to get rid of? What causes it? Does the remote host print a host banner or some such? Does .hushlogin help? Commented Apr 19, 2016 at 18:00
  • If i do that it will clear the string value.. Commented Apr 19, 2016 at 18:01

1 Answer 1

1

Try turning off STDERR in the command.

string=$(su - user -c "ssh $L_NAME 'cat ~/.ssh/known_hosts'" 2>&-) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.