[CLUE-Tech] shell programming

David Guntner davidg at akaMail.com
Wed Dec 11 04:13:16 MST 2002


On Wed, Dec 11, 2002 at 09:48:32AM -0100, Marcin wrote:
> 
>  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.

You're looking at the wrong variable.  You want to use $LOGNAME instead of 
$user.  Thus:

#!/bin/bash

if [ $LOGNAME = "root" ]; then
  echo "Hello root"
else
  echo "You aren't root"
fi


Will do what you want.

                 --Dave
-- 
      David Guntner      GEnie: Just say NO!
 http://www.akaMail.com/pgpkey/davidg or key server
                 for PGP Public key




More information about the clue-tech mailing list