BASH Scripting

FireDrow

New Member
I'm using SuSE linux to run couple servers in my dorm. I wrote a script a while back so I could quickly add users and give them web dirs, Samba access, etc. Well I tried adding in a root-only function to the start of the script but it doesn't seem to work.

if [ 'id -u' != "0" ]; then
echo "You do not have root access"
exit 1
else
clear
echo -n "Which user would you like to work with > "
read user
fi

Does anyone know enough about BASH scripting to see the error?
 

SFR

Truth fears no questions
I am no expert in BASH ....

but... like [tab] said...

if those are single quotes and u want to use command subtitution the backticks ` ` will work.... even though u see more and more of $( ) used today..



BEST BET:

if [ $(id -u) = 0 ] ; then
 
Last edited:

FireDrow

New Member
I've tried using both ticks ( ` ) and single quotes ( ' ). Neither worked. I also tried the $(id -u) that was suggested and I get the same results.

I could email it to someone if you want a better look.
 

SFR

Truth fears no questions
well I know this is stupid but make sure #!/bin/bash is in there

May I ask why u need the exit 1?


the answer is true it will:

echo "You do not have root access"


and then get out of the if. Otherwise it will:

clear
echo -n "Which user would you like to work with > "
read user



and are you reading from a file or is that just imput for you to type in?
 
Top