my problem I have to write on a single line a command to launch a script only if the number of users on the system is less than ten.
This is what I have so far.
grep | who "* < 10 " $Users-on
I always get confused about quotes and brackets
The syntax is different according for each shell, but if you are using the bash shell you could try the following:
if [ `who | wc -l` -lt 10 ]; then
echo "less than";
echo " more than";
which can be written as one line as well, but i don't know what difference that would make.
if [ `who | wc -l` -lt 10 ]; then echo "less than"; else echo " more than"; fi
the point is that you need two programs, one that lists the users: who and one that counts lines wc.
wc is actually a word counting program, but with the -l flag it counts lines
The execution inverted comma's '`' mean to take the textual result and use it as a variable. That is the number that is returned from word count should be used as a variable.
The if statement uses the -lt flag, which stands for less than
so if [ `who | wc -l` -lt 10 ]
means if the the number of lines of the who output is less than 10, then perform the following action ...
in our case just echoing out to the screen, but you will want to run your program there