Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Let's say we run two programs in the Linux shell, on one line, like this:

who -r; date

What should I add to obtain one line output?

share|improve this question
1  
ok, I got it. That works like a charm: echo who -r; date –  biera Aug 30 '12 at 22:19
    
should have been: echo `who -r; date` –  biera Aug 30 '12 at 23:06
    
You should attempt to ask an actual question in the title of your post since that will get you a lot more attention... –  Max Vernon Aug 31 '12 at 13:53
    
Ok Max. I will consider this next time! –  biera Sep 1 '12 at 19:09

2 Answers 2

up vote 5 down vote accepted
printf "%s %s\n" "$(who -r)" "$(date)"

Lots of quotes, but all are required. More simply:

echo $(who -r; date)

This one purposefully has no quotes.

share|improve this answer
echo -n `who -r`; echo -n ' '; date
share|improve this answer
2  
If at all possible, get in the habit of using $( ... ) instead of `...`. That way, it's easy to capture the output of a command taht uses captured output. If you use backticks, it's almost impossible. –  Vatine Aug 31 '12 at 1:26
    
@Vatine plus, it's far far easier to read, and it doesn't confuse serverfault's parsing. Better all around. –  Gordon Davisson Aug 31 '12 at 7:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.