From owner-freebsd-questions Tue Aug 14 16:54:57 2001 Delivered-To: freebsd-questions@freebsd.org Received: from lcmail2.lc.ca.gov (lcmail2.lc.ca.gov [165.107.12.11]) by hub.freebsd.org (Postfix) with ESMTP id 5BA7337B406 for ; Tue, 14 Aug 2001 16:54:47 -0700 (PDT) (envelope-from drewt@writeme.com) Received: from CONVERSION-DAEMON by lcmail2.lc.ca.gov (PMDF V5.2-27 #40821) id <0GI300A01142LH@lcmail2.lc.ca.gov> for freebsd-questions@FreeBSD.org; Tue, 14 Aug 2001 16:55:16 -0700 (PDT) Received: from tagalong ([165.107.42.215]) by lcmail2.lc.ca.gov (PMDF V5.2-27 #40821) with SMTP id <0GI3009OQ140PV@lcmail2.lc.ca.gov> for freebsd-questions@FreeBSD.org; Tue, 14 Aug 2001 16:55:12 -0700 (PDT) Date: Tue, 14 Aug 2001 16:53:43 -0700 From: Drew Tomlinson Subject: RE: Shell Script Help - Comparing Strings In-reply-to: <5CD46247635BD511B6B100A0CC3F0239E342B5@ldcmsx01.lc.ca.gov> To: 'parv' Cc: "'FreeBSD Questions (E-mail)'" Message-id: <5CD46247635BD511B6B100A0CC3F023925A06B@ldcmsx01.lc.ca.gov> MIME-version: 1.0 X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 X-Mailer: Microsoft Outlook CWS, Build 9.0.2416 (9.0.2911.0) Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit Importance: Normal X-Priority: 3 (Normal) X-MSMail-priority: Normal 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 > -----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 > > > this was, on the fateful occasion around Aug 14 18:43 -0400, > sent by Drew Tomlinson > > > > As I continue in writing my first shell script, I can't > figure out how to > > compare strings properly. For example, I want to run my > script and pass an > > argument to it from the command line. However, if this > argument is not > > passed, then I want to set it to a defined value. I'm > trying to use the if > > statement for this. Here's a clip of my code: > > > > #! /bin/sh -vx > > > > # 8/8/01 > > # An attempt to write script to run webalizer to generate > web stats for all > > # virtual web sites. > > > > # Set command line variables. $1 = web to run. > > > > # Set $1 to "www" if blank. > > echo $1 > > if ["$1"=""] > > then $1 = "www" > > fi > ... > > > echo $1 > > + echo test > > test > > if ["$1"=""] > > then $1 = "www" > > fi > > + [test=] > > [test=]: not found > ... > > 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. > ...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! I'm sure I'll come across it when I get into this further. I've only had a intro unix class so I only experienced the very basics. Thanks, Drew To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message