From owner-freebsd-questions Tue Aug 14 17:29: 1 2001 Delivered-To: freebsd-questions@freebsd.org Received: from mtiwmhc22.worldnet.att.net (mtiwmhc22.worldnet.att.net [204.127.131.47]) by hub.freebsd.org (Postfix) with ESMTP id 9C4A137B408 for ; Tue, 14 Aug 2001 17:28:55 -0700 (PDT) (envelope-from parv@worldnet.att.net) Received: from worldnet.att.net ([32.100.199.151]) by mtiwmhc22.worldnet.att.net (InterMail vM.4.01.03.16 201-229-121-116-20010115) with ESMTP id <20010815002854.WJFO15499.mtiwmhc22.worldnet.att.net@worldnet.att.net>; Wed, 15 Aug 2001 00:28:54 +0000 Received: by worldnet.att.net (Postfix, from userid 1001) id C5EAE50EEF; Tue, 14 Aug 2001 20:28:30 -0400 (EDT) Date: Tue, 14 Aug 2001 20:28:30 -0400 From: 'parv' To: Drew Tomlinson Cc: "'FreeBSD Questions (E-mail)'" Subject: Re: Shell Script Help - Comparing Strings Message-ID: <20010814202830.A67894@moo.holy.cow> Mail-Followup-To: Drew Tomlinson , "'FreeBSD Questions (E-mail)'" References: <5CD46247635BD511B6B100A0CC3F0239E342B5@ldcmsx01.lc.ca.gov> <5CD46247635BD511B6B100A0CC3F023925A06B@ldcmsx01.lc.ca.gov> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5CD46247635BD511B6B100A0CC3F023925A06B@ldcmsx01.lc.ca.gov>; from drewt@writeme.com on Tue, Aug 14, 2001 at 04:53:43PM -0700 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG this was, on the fateful occasion around Aug 14 19:53 -0400, sent by Drew Tomlinson > > > -----Original Message----- > > From: parv [mailto:parv_@yahoo.com] > > Sent: Tuesday, August 14, 2001 4:12 PM > > To: Drew Tomlinson > > Cc: FreeBSD Questions (E-mail) > > Subject: Re: Shell Script Help - Comparing Strings > > > > ... > > you need to add spaces between test operators... > > > > if [ "$1"="" ] # notice the difference > > then > > $1="www" > > fi > > I see but this didn't work for me either. This is what I get. > > if [ "$1"=="" ] #Tried with both single and double "=" > then $1="www" > fi > + [ test== ] > + test=www > test=www: not found > > Another poster explained that "=" sets a value but "==" should be used for > comparing strings. I tried it both ways but got the same error. believe it or not, that's progress. error is not in the if condition but in the variable assignment. you shouldn't have a '$' in there. i missed it first time around... guess i was not thinking deep... now, if you remove '$', then you will still get another error; there may be a some way to assign a value to a positional parameter, but in your case, work isn't worth it. instead of assigning something to $1, use a letter/word variable like shown below. > > ...but i would test the number of arguments, and set a non positional > > variable instead... > > > > case $# in > > 0) > > suffix=www > > ;; > > > > *) > > suffix=$1 > > ;; > > esac > > > > ...but still better alternative, would be... > > > > suffix=${1:-www} > > This is stuff I don't understand but thank you for sharing! btw, another way to write that if condition... if [ -z "$1"] # true if length is zero then ... fi you should take a look at test(1) and sh(1). -- so, do you like word games or scrabble? - parv To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message