You are not logged in.

#1 2011-05-16 18:25:30

rickeyski
Member
Registered: 2011-01-27
Posts: 25

bash help [solved]

Hi,

I'm writing a bash script and I am trying to test 2 strings in the same if statement, and it doesnt read the second statement,

if [ "$1" != "dbstart" -o "$1" != "dbstop" ]
then
  echo 'use dbstart or dbstop'
else
  su - postgres -c "sh ${1}.sh"
fi

I have also tried || with no success.  The only way to make this work is to use a separate elif statement for each string.

So, is the "or" impossible or did I miss something really stupid?? thanks

Last edited by rickeyski (2011-05-16 19:05:08)

Offline

#2 2011-05-16 18:50:54

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: bash help [solved]

I think you want "and", not "or".

if [ "$1" != "dbstart" -a "$1" != "dbstop" ]

Offline

#3 2011-05-16 19:04:03

rickeyski
Member
Registered: 2011-01-27
Posts: 25

Re: bash help [solved]

ahh thanks, dyslexic am i

Offline

#4 2011-05-17 16:12:00

Stalafin
Member
From: Berlin, Germany
Registered: 2007-10-26
Posts: 617

Re: bash help [solved]

I would not use [ ] tests though. If you are writing bash, use [[ ]] instead!

Offline

Board footer

Powered by FluxBB