Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash : Illegal number

Tags:

bash

shell

When I run this bash script :

if [ [$EUID -ne 0] ]; then
   echo "This script must be run as root" 1>&2 
   exit 1
else 

printf " whathever "

exit 0 
fi

I have this error :

./myScript: 15: [: Illegal number: [

Do you see any problem ?

like image 981
4m1nh4j1 Avatar asked Oct 25 '13 19:10

4m1nh4j1


People also ask

What does [- Z $1 mean in bash?

$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script. Follow this answer to receive notifications.

Is it true 1 or 0 bash?

There are no Booleans in Bash. However, we can define the shell variable having value as 0 (“ False “) or 1 (“ True “) as per our needs.

What is $1 and $2 in bash?

$0 is the name of the script itself (script.sh) $1 is the first argument (filename1) $2 is the second argument (dir1)

What is $@ in bash?

bash [filename] runs the commands saved in a file. $@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc.


1 Answers

You have syntax error in your if condition, use this if condition:

if [ "$EUID" -ne 0 ];

OR using [[ and ]]

if [[ "$EUID" -ne 0 ]];
like image 109
anubhava Avatar answered Oct 17 '22 08:10

anubhava