I have a script file like this:


echo "The script starts now."
echo "Hi, user!"

echo "I will now fetch you a list of connected users:"

echo "I'm setting two variables now."

echo "This is a string: $COLOUR"
echo "And this is a number: $VALUE"

I observed that the effect of w is that it prints the following:

 18:06:36 up  7:43,  3 users,  load average: 0.40, 0.56, 0.64
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
hes      tty7                      10:23    7:43m 12:31   0.96s gnome-session -
hes      pts/0    :0               15:41    4.00s  1.38s 11.46s gnome-terminal
hes       pts/2    :0               17:20   44:52   0.79s 11.46s gnome-terminal

when I typed echo " statement" in terminal , it prints the statement. But I could not understand w here. in terminal echo w , prints w not as above. Can someone help me in understanding how this work?

  • 1
    Please see man w
    – andr3w
    Jan 6 '14 at 12:52
  • Oh, I did not know this one character command!! Thanks for your help. Jan 6 '14 at 13:03
  • Note: there is no difference between a "string" and a "number" in bash. Even declare -i does not change type, it just artificially adds limitations.
    – Chris Down
    Jan 6 '14 at 13:08

I really don't understand what you're doing. w is a command and your scriptis running it, what were you expecting?

## This echo prints the string within the quotes: "I will ..."
echo "I will now fetch you a list of connected users:"
## This echo prints an empty line
## This runs the command 'w' which prints connected users

echo w on the other hand will simply print the letter w since you are not running the command. If you want to echo the command's output, run echo $(w). That, however, is pointless since it will loose the formatting and simply running w is enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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