[CLUE-Tech] shell programming

Marcin marbej at wp.pl
Wed Dec 11 03:48:32 MST 2002


Hello,

I don't understand something.
I've written something like this:

#! /bin/bash
if [ $user="root" ]
then
	echo "Hello root"
else
	echo "You aren't a root"
fi

I'm loged in as user e.g. Orion and if I run this script I get "Hello 
root", but I'm not a root only user Orion.
If I correct second line (add sign "!") :
if [ ! $user="root" ] 
then my script works OK and when I run it I get "You aren't a root"
Why this script works OK only with the sign "!" ?
But if I now do command "su root" and I became a root and run this 
script as root it again doesn't work OK :-( I get "You aren't a root"
Do someone know this and could explain me?
How I should write this script?
I use RH 7.3 and bash shell.

-- 
Greetings from Poland,
Marcin Betlej
e-mail: marbej at wp.pl



More information about the clue-tech mailing list