Echo and a command's output on the same line

Hello,

I'm writing some bash scripts and I'm trying to get an echo command and the output of another command to display on the same line. For example:

I want to run

echo "Operating System: " uname

and have it displayed as

Operating System: Darwin

Thanks for your help!

Use 1 of the 2 command substitutions.

Backtick expansion:

echo "Operating System: " `uname`

or brace expansion:

echo "Operating System: " $(uname)

Or if the "-n" option works in your system, then -

echo -n "Operating System: "; uname

tyler_durden

Or, if you can change away from echo, use printf

printf 'Operating System: %s\n' $( uname )
printf "Operating System: $( uname )\n"

Thanks! That helps a lot. Is it possible to limit the output from the command in ' ' to a certain number of characters or to one line?

It's not really clear what you're asking for, can you elaborate your question a little more?

Sure. Here's an example:

echo "This is my current directory: " 'pwd'

Then the output would be

This is my current directory: /Users/codyhazelwood/Dropbox
/Photos/Sample Album

But, I would like to truncate that output so it's only on one line instead of running down onto a second line.

Thanks

I don't see this happening in my system. I think it might've something to do with the size of your terminal emulator/console window.

Maybe the window is too small due to which the line wraps around. You may want to check a couple of things by clicking on the "properties" or "preferences" menu-item:

(a) increase the horizontal size of the window
(b) see if there's an option to add a horizontal scroll bar
(c) see if there's an option to not wrap long lines
(d) if the font size could be made smaller
(e) if you could drag the lower right corner of the window to make it larger

HTH,
tyler_durden