LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-03-2005, 10:49 AM   #1
ronsha
Member
 
Registered: Oct 2005
Posts: 30

Rep: Reputation: 15
simple question from newbie. sorry !


Hi,

I'm currently studying shell scripting and I have a small problem with a very simple script. I know a lot of you will consider this very easy but I can't see the problem.

I wrote a script that aim to count all the users registred in the system and will echo a string based on the amount of users(greater on smaller than the argument passed to the scrip).
Here is what I wrote:

#!/bin/sh
number=$1
all_users=`cut -d: -f1 /etc/passwd | wc -l`
if [ $all_users>$number ]; then
echo "More than $number users in the system"
else
echo "Less than $number users in the system"
fi

Can any of you see the problem before I say what it is??

For those who don't see it - I always get that there are more users than my input even if the argument is larger than the actual registred users.
 
Old 12-03-2005, 11:10 AM   #2
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
Quote:
if [ $all_users>$number ]; then
Try this:

Code:
if [ $all_users -gt $number ]; then
Similarly, it's also possible to use -lt (less than), -ge (greater or equal) -eq (equal) or -le (less than or equal).
I think that's all of them.
 
Old 12-03-2005, 11:15 AM   #3
ronsha
Member
 
Registered: Oct 2005
Posts: 30

Original Poster
Rep: Reputation: 15
thanks. that did the trick !

Does this mean the shell doesn't support these operators: < > = >= <= ?
 
Old 12-03-2005, 11:20 AM   #4
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
Hmm, one thing that I'd forgotten was you could have written something like (($all_users > $number)), which should work. If you use the square brackets though, then <, > etc won't work on numbers. This page explains things better than I probably can.
 
  


Reply



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
Simple newbie question - how to... mazzo Linux - Wireless Networking 4 09-02-2004 03:34 PM
simple newbie question naijaguy Red Hat 1 08-11-2004 10:55 PM
Simple newbie question izrahi Linux - Newbie 1 08-11-2004 05:07 PM
Iptables newbie / simple question wr3ck3d Linux - Networking 2 03-06-2003 08:08 AM
A simple newbie question ! trubi Linux - General 19 01-30-2003 08:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:19 PM.

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
Open Source Consulting | Domain Registration