PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 17, 2022

[FIXED] How to echo a variable following a string in bash?

 August 17, 2022     bash, io-redirection, openssh, output, stderr     No comments   

Issue

I need to print the output of the "ssh -V" command inbetween some xml nodes. I want it to look like

<sshname>OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017</sshname>

but the code below is printing the command's output before the nodes.

sshname=$(ssh -V)
echo "<sshname> $sshname</sshname>"

Result:

OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
<sshname> </sshname>

Why is that happening? and how can I get around it?


Solution

Redirect ssh's stderr (2) to stdout (1), too:

sshname=$(ssh -V 2>&1)

See: https://en.wikipedia.org/wiki/Standard_streams



Answered By - Cyrus
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing