Hi all,
I am very new to shell scripting. I wrote this simple script to check if the user is root:
And here's the output:
Why isn't the "ls -l" not working in the "if" block? Where am I going wrong? Has it got something to do with the syntax of the if block?
Regards,
Ven.
I am very new to shell scripting. I wrote this simple script to check if the user is root:
Code:
#!/bin/bash
curr_user=`whoami`
ls -l
if [ curr_user = 'root' ]
then
echo 'you are root'
ls -l
echo 'you are root 2'
else
echo "you are $curr_user."
echo "you are $curr_user 2."
fi
exit
Code:
vc@linux-3o76:~/work> ./a.sh
total 4
-rwxrwxrwx 1 vc users 195 Aug 15 09:21 a.sh
you are vc.
you are vc 2.
vc@linux-3o76:~/work> sudo ./a.sh
total 4
-rwxrwxrwx 1 vc users 195 Aug 15 09:21 a.sh
you are root.
you are root 2.
vc@linux-3o76:~/work>
Regards,
Ven.