Shell script newbie, what is problem with my script?

Hello,
Ubuntu server 11.10
can anybody help what is problem with my shell script?

#!/bin/bash
#script to find out currently logged on user is root or not.
if [[$EUID -eq 0]]
then
echo "You are super"
else
echo "You are awesome!"
fi

When I run script, I get following output

./uid: line 3: [[0 command not found
You are awesome!

I tried putting single quotes and double quotes around 0 but same error.
Also one more question "What is difference between echo * and ls?" (Sorry not related to subject)

Consider [[ and ]] to be like commands, not brackets. [[0 is not the same command as [[ . So you need to add some spaces:

if [[ $EUID -eq 0 ]]
1 Like

Thanks! it worked! What about second question?

Sorry, I missed your second question.

There's two differences.

  • ls prints lines of text. * sets arguments.
  • ls is an external program. * is a shell operator.

Arguments are the things you feed into a program, like so:

./myprogram 1 2 3

argument 1 would be 1, and so forth.

'echo' doesn't actually understand what * means. The shell translates * into a list of files for you, before the program is run. So you can use * anywhere a list of file arguments makes sense!

ls on the other hand, reads filenames by itself. It also has options to sort them (-t means sort by time ), and print extended information ( -l ) which * cannot do.

Surely you can research:

There are subtle differences across versions of both commands depending on the version of unix/Linux.