LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-27-2009, 09:20 AM   #1
mrbutabara
Member
 
Registered: Jan 2007
Location: Stafford, VA
Distribution: Ubuntu
Posts: 32

Rep: Reputation: 15
scripting question.


just started linux this college semester. wanting to know how to write a line so that the output will be on the same line in the display.

example

echo "Number of user login:"; who | wc -l

it will display it as

Number of user login:
1

i want to know how to get it to display as

Number of user login: 1

any suggestions? thanks in advance.
 
Old 01-27-2009, 09:25 AM   #2
zer0x333
Member
 
Registered: Oct 2007
Posts: 31

Rep: Reputation: 16
backticks

Hi,

Try..

Code:
echo "number of users: `who | wc -l`"
Those are backticks not punctuation marks xD

Cheers,
zer0x
 
Old 01-27-2009, 09:26 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Look at the man page of the echo command and see if you find an useful option to do that. Moreover, you may consider the printf command to get a fine formatting of the terminal output.

You see, I can't give the complete answer since this is declared as homework, just a small direction that I hope it may be useful.

Edit: ...come non detto....(as never told)...!!

Last edited by colucix; 01-27-2009 at 09:27 AM.
 
Old 01-27-2009, 09:29 AM   #4
zer0x333
Member
 
Registered: Oct 2007
Posts: 31

Rep: Reputation: 16
Quote:
Originally Posted by colucix View Post
You see, I can't give the complete answer since this is declared as homework, just a small direction that I hope it may be useful.
My bad, too late now I guess.. and I probably should have used the echo option...
 
Old 01-27-2009, 09:31 AM   #5
mrbutabara
Member
 
Registered: Jan 2007
Location: Stafford, VA
Distribution: Ubuntu
Posts: 32

Original Poster
Rep: Reputation: 15
@ zero
thanks a lot. solved my problem

@colucix
not really homework. it was in our notes, but we (the class and teacher) couldn't figure it out.
 
Old 01-27-2009, 09:38 AM   #6
zer0x333
Member
 
Registered: Oct 2007
Posts: 31

Rep: Reputation: 16
Quote:
Originally Posted by mrbutabara View Post
not really homework. it was in our notes, but we (the class and teacher) couldn't figure it out.
Your teacher couldn't work it out!?

In case you wanted to know, the echo option is -n (dont output trailing newline).

Cheers,
zer0x
 
Old 01-27-2009, 09:40 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Quote:
Originally Posted by mrbutabara View Post
@colucix
not really homework. it was in our notes, but we (the class and teacher) couldn't figure it out.
You sure he/she is a linux teacher?!?

Anyway, you can either use
Code:
echo -n "Number of user login: "; who | wc -l
where the -n option prevents echo to output the trailing newline so that further output is kept on the same line, OR
Code:
echo "Number of user login: $(who | wc -l)"
as suggested by zer0x333, with the slight difference that I used the syntax $(...) to do command substitution, OR
Code:
printf "Number of user login: %s\n" $(who | wc -l)
using the printf statement. And please, reject that teacher....!!!!!
 
Old 01-27-2009, 09:40 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Quote:
Originally Posted by zer0x333 View Post
Your teacher couldn't work it out!?

In case you wanted to know, the echo option is -n (dont output trailing newline).

Cheers,
zer0x
zer0x beat me twice in a thread!
 
Old 01-27-2009, 09:43 AM   #9
zer0x333
Member
 
Registered: Oct 2007
Posts: 31

Rep: Reputation: 16
Quote:
Originally Posted by colucix View Post
zer0x beat me twice in a thread!
Lol, sry colucix xP You did put it so much more eloquently than me though xD
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
scripting question kpachopoulos Programming 1 03-03-2006 01:03 PM
scripting question... Basslord1124 Linux - Networking 2 11-09-2005 05:52 AM
Scripting question mithereal Linux - General 2 09-21-2005 02:02 AM
Scripting question msandford Linux - Newbie 4 09-05-2005 10:23 AM
Scripting Question Darklight451 Linux - Newbie 4 11-12-2004 11:14 AM


All times are GMT -5. The time now is 05:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration