From owner-freebsd-questions Tue Aug 14 16:12:55 2001 Delivered-To: freebsd-questions@freebsd.org Received: from mtiwmhc21.worldnet.att.net (mtiwmhc21.worldnet.att.net [204.127.131.46]) by hub.freebsd.org (Postfix) with ESMTP id 047F637B40A for ; Tue, 14 Aug 2001 16:12:51 -0700 (PDT) (envelope-from parv@worldnet.att.net) Received: from worldnet.att.net ([32.100.199.151]) by mtiwmhc21.worldnet.att.net (InterMail vM.4.01.03.16 201-229-121-116-20010115) with ESMTP id <20010814231249.TVTB12706.mtiwmhc21.worldnet.att.net@worldnet.att.net>; Tue, 14 Aug 2001 23:12:49 +0000 Received: by worldnet.att.net (Postfix, from userid 1001) id 3A70550D30; Tue, 14 Aug 2001 19:12:14 -0400 (EDT) Date: Tue, 14 Aug 2001 19:12:14 -0400 From: parv To: Drew Tomlinson Cc: "FreeBSD Questions (E-mail)" Subject: Re: Shell Script Help - Comparing Strings Message-ID: <20010814191214.A55329@moo.holy.cow> Mail-Followup-To: Drew Tomlinson , "FreeBSD Questions (E-mail)" References: <5CD46247635BD511B6B100A0CC3F023925A069@ldcmsx01.lc.ca.gov> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5CD46247635BD511B6B100A0CC3F023925A069@ldcmsx01.lc.ca.gov>; from drewt@writeme.com on Tue, Aug 14, 2001 at 03:43:31PM -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 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 ...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} -- 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