Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if command help 2

Status
Not open for further replies.

lpblauen

Technical User
Dec 2, 2004
193
US
I'm having a brain problem this should be simple but I'm having problem figuring it out.
I have a script and I want it to check for arguments if none tell valid agrument and exit. Got that working. Now if the valid argument passed do something. If not stop. Here is where I'm brain dead.
Here is the simple script.

if [ ! "$1" ]
then
echo "Valid arguments are attack | test"
exit 1
else
if [ "$1" = attack ]
then
C=userdel
fi
if [ "$1" = test ]
then
C=" "
fi
if [ "$1" ! attack -o test ]
then
echo " I'm here"
exit 1
fi
fi
The first two if's work fine. Its the last if I'm stuck on. If the arguments are not attack or test exit 1. The script at this point keeps going. I thought the -o was a logical not. If its not attack or test exit 1 is what I'm tring to do. I know its simple I just can't remember the right way to put it. Thanks for any help.
 
Perhaps something like this ?[tt]
case "$1" in
attack) C=userdel;;
test) C=" ";;
*) echo "Valid arguments are attack | test"; exit 1
esac[/tt]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi

Code:
if [ ! "$1" ]
then
  echo "Valid arguments are attack | test"
  exit 1
else

case "$1" in
  attack)
    C=userdel
  ;;
  test)
    C=" "
  ;;
  *)
    echo " I'm here"
    exit 1
  ;;
esac

Feherke.
 
That works. Thanks PHV. Feherke yours also worked but I had to add a fi to the end and after echo "I'm here" ; exit1 ;;
Then it worked too. Now I'm just curious could this be done using if? if [ "$1" != attack -o test ]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top