PMoran
PMoran

Reputation: 1

How do I concatenate the result of two linux commands and have the result on one line?

I want to run two linux commands such as :

whoami && stat -c %i "/home"

But I want the result to be

user 123456

(all on one line without a break in the line).

Upvotes: 0

Views: 255

Answers (2)

David C. Rankin
David C. Rankin

Reputation: 84561

If using bash (or any other shell that supports arrays), you can use an array as well. Simply store the output from your original compound command in an array using command substitution:

$ var=( $(whoami && stat -c %i "/home") ); echo "var '${var[@]}'"
var 'david 2'

Upvotes: 1

user3553031
user3553031

Reputation: 6214

Try capturing the results of both of your commands and using something else to format them into a single line. This should do the trick:

echo `whoami` `stat -c %i "/home"`

Upvotes: 1

Related Questions