Shell scripting.

Was wondering if someone could help me out. I get this error message each time I try to execute the code underneath.

/home/demon/some.sh: line 8: [: too many arguments

-------------------------------
Script contents:
-------------------------------

#!/bin/bash

SOME=`whoami`
echo $SOME

USER=`w -h |awk '{ print $1 }' |sort |wc`

if [ $USER = 5 ]; then
   grep $SOME 
fi

What I want to do is:
That the script stores the output of the whoami command in a
variable. Then, if the number of users logged into the system (not
unique) is equal to 5, it should grep /etc/passwd for
the contents of the variable I created above.

Any help thxz. Yeah you can post a complete new code don't mind.

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

---------- Post updated at 07:31 AM ---------- Previous update was at 07:27 AM ----------

#!/bin/bash

me=$(whoami)
echo $me

USERS=$(w -h |awk '{ print $1 }' |sort -u|wc -l)

if [ "${USERS}" -eq 5 ]; then
   awk -v me="${me}" -F: '$1 == me' /etc/passwd 
fi

Ok will do in the future.

BTW I get these errors with the code you supplied.

line 1: USERS: command not found
line 8: [: : integer expression expected

works fine under Sun/Solaris.
Please post the exact script and error(s) encountered (using code tags).

---------- Post updated at 07:58 AM ---------- Previous update was at 07:55 AM ----------

try this:

#!/bin/bash
#set -x

me=$(whoami)
echo $me

typeset -i USERS=$(w -h |awk '{ print $1 }' |sort -u|wc -l)

if [ "${USERS}" -eq 5 ]; then
   awk -v me="${me}" -F: '$1 == me' /etc/passwd
fi

Just did some checking but still get these errors now...

line 1: USERS: command not found
line 8: [: : integer expression expected

I am running on CentOS re. 3.7.

see my last posting.

With this code I still get the above errors...

#!/bin/bash
#set -x

me=$(whoami)
echo $me

typeset -i USERS=$(w -h |awk '{ print $1 }' |sort -u|wc -l)

if [ "${USERS}" -eq 5 ]; then
   awk -v me="${me}" -F: '$1 == me' /etc/passwd
fi

make sure you're using the correct snippet quoted above.
uncomment out the '#set -x', re-run the script and post the output, please.

Hey mate, thanks a lot for all the help!

It is working now!

~D~