Article View: comp.unix.shell
Article #4035Using an If Statement to Check One of Three Possible Values
From: kvnsmnsn
Date: Tue, 11 Jul 2006 20:20
Date: Tue, 11 Jul 2006 20:20
37 lines
2459 bytes
2459 bytes
I'm trying to build a bash script that creates an "x.java" and a
"y.java" file from three existing pairs of files, depending on whether
an "a", a "b", or a "c" is entered on the command line. My bash code
checks to see if the number of arguments entered on the command line
is one, which check it handles fine, but if it passes that check and
goes on to the next "if" statement, it gives me the complaints:
Hmm.sh: line 4: [: missing `]'
Hmm.sh: line 4: a: command not found
Hmm.sh: line 4: a: command not found
Incorrect operand "a".
My actual code is:
#! /bin/sh
if [ $# == 1 ]
then
if [ $1 == "a" || $1 == "b" || $1 == "c" ]
then
cp x_$1.java x.java
cp y_$1.java y.java
else
echo "Incorrect operand \"$1\"."
fi
else
echo "Usage is"
echo " sh Hmm.sh <suffix>"
fi
Can anyone see what I'm doing wrong here? Any pointers would be
greatly appreciated.
---Kevin Simonson
"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
Technical Details
Message-ID:
<1152649211.167708.83330@m79g2000cwm.googlegroups.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!m79g2000cwm.googlegroups.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 1012a6,451bb3cca7eb9094,start X-Google-Thread: 1054c0,451bb3cca7eb9094,start X-Google-Thread: 114230,451bb3cca7eb9094,start X-Google-Attributes: gid1012a6,gid1054c0,gid114230,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!m79g2000cwm.googlegroups.com!not-for-mail From: kvnsmnsn@hotmail.com Newsgroups: comp.unix.shell,gnu.bash,alt.comp.lang.shell.unix.bourne-bash Subject: Using an If Statement to Check One of Three Possible Values Date: 11 Jul 2006 13:20:11 -0700 Organization: http://groups.google.com Lines: 38 Message-ID: <1152649211.167708.83330@m79g2000cwm.googlegroups.com> NNTP-Posting-Host: 128.187.80.2 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1152649216 24396 127.0.0.1 (11 Jul 2006 20:20:16 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 11 Jul 2006 20:20:16 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; rv:1.7.3) Gecko/20041020 Firefox/0.10.1,gzip(gfe),gzip(gfe) X-HTTP-Via: 1.1 firewall.cs.byu.edu:3128 (squid/2.5.STABLE6) Complaints-To: groups-abuse@google.com Injection-Info: m79g2000cwm.googlegroups.com; posting-host=128.187.80.2; posting-account=CSI2ywwAAAA26jBcDTrzMQSP_nlx1sGA