Gentoo Archives: gentoo-user

From: Michael Sullivan <michael@××××××××××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] OT - Question about conditionals and bash scripting
Date: Thu, 12 Oct 2006 21:14:20
Message-Id: 1160687302.12701.25.camel@camille.gateway.2wire.net
In Reply to: Re: [gentoo-user] OT - Question about conditionals and bash scripting by Richard Broersma Jr
1 On Thu, 2006-10-12 at 13:49 -0700, Richard Broersma Jr wrote:
2 > > I have a short script:
3 > >
4 > > #!/bin/bash
5 > >
6 > > while read LINE
7 > > do
8 > > whois $LINE | grep 'abuse' &> /dev/null
9 > > if $? != 0; then
10 > > echo "$LINE" >> noabuse.txt
11 > > fi
12 > > done < iplist
13 > >
14 > > I'm getting "command not found" on the if line. Have I not formatted it
15 > > correctly? The script is supposed to append $LINE to a file if the
16 > > return code of whois $LINE | grep 'abuse' returns false (not 0)...
17 > >
18 >
19 > Do you need to add
20 > if test...
21 > or if [ ... ]?
22 >
23 > Regards,
24 >
25 > Richard Broersma Jr.
26
27 OK. Here's my new code:
28
29 #!/bin/bash
30
31 while read LINE
32 do
33 whois $LINE | grep 'abuse' &> /dev/null
34 if [$? -ne 0]; then
35 echo "$LINE" >> noabuse.txt
36 fi
37 done < iplist
38
39 Here's the output:
40
41 michael@bullet ~/.maildir/.SPAM/cur $ ./process.sh
42 ./process.sh: line 6: [1: command not found
43 ./process.sh: line 6: [1: command not found
44 ./process.sh: line 6: [1: command not found
45 Interrupted by signal 2...
46
47
48 --
49 gentoo-user@g.o mailing list

Replies

Subject Author
Re: [gentoo-user] OT - Question about conditionals and bash scripting Richard Broersma Jr <rabroersma@×××××.com>
Re: [gentoo-user] OT - Question about conditionals and bash scripting "Brett I. Holcomb" <brettholcomb@×××××××××.net>
Re: [gentoo-user] OT - Question about conditionals and bash scripting "Bo Ørsted Andresen" <bo.andresen@××××.dk>
Re: [gentoo-user] OT - Question about conditionals and bash scripting alain.didierjean@××××.fr