Date: Tue, 14 Aug 2001 15:43:31 -0700 From: Drew Tomlinson <drewt@writeme.com> To: "FreeBSD Questions (E-mail)" <freebsd-questions@FreeBSD.org> Subject: Shell Script Help - Comparing Strings Message-ID: <5CD46247635BD511B6B100A0CC3F023925A069@ldcmsx01.lc.ca.gov>
next in thread | raw e-mail | index | archive | help
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 web="$1.mykitchentable.net" odir="/usr/local/www/data/webalizer/$1" logfile="/var/log/$1-access.log" echo $web echo $odir echo $logfile exit Now when I run this passing the argument of "test", here is my output: blacklamb# ./webalizer_run.sh test #! /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 + echo test test if ["$1"=""] then $1 = "www" fi + [test=] [test=]: not found web="$1.mykitchentable.net" + web=test.mykitchentable.net odir="/usr/local/www/data/webalizer/$1" + odir=/usr/local/www/data/webalizer/test logfile="/var/log/$1-access.log" + logfile=/var/log/test-access.log echo $web + echo test.mykitchentable.net test.mykitchentable.net echo $odir + echo /usr/local/www/data/webalizer/test /usr/local/www/data/webalizer/test echo $logfile + echo /var/log/test-access.log /var/log/test-access.log exit + exit So my error seems to be in the if statement. Can anyone explain what I'm doing wrong? Thanks, Drew To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5CD46247635BD511B6B100A0CC3F023925A069>