| | |
Subshell Problem, syntax error...Help please!
![]() |
•
•
Join Date: Dec 2004
Posts: 8
Reputation:
Solved Threads: 0
Hello, I am getting a syntax error with a shell script of mine that is eluding me...I am pretty new to this so if someone could help me out I'd appreciate it. Here is the part of the script that is throwing the error:
It complains about the closing ) after the while loop.
The exact error is:
"./wireless_pcx_shell[33]: [: 0: unexpected operator/operand"
Is there something that I am doing wrong here? Any help would be great, thanks everyone.
#!/bin/ksh
# Kismet/PCX Loader
#
.
.
.
set count = 0
set stat = 1
# while output pipe cannot be opened, keep trying to open it. stop after 10 seconds (5 tries)
# run the two concurrently
# /root/kismet-2004-04-R1/kismet_server
# kismet_server & bash ; cd /home/bang/dev/3.x/rtpcx/bin/x86_og/
(kismet_server) &
(
cd /home/bang/dev/3.x/rtpcx/bin/x86_og/
while [ $stat -gt 0 ]
do
# echo "+++++ GOT IN HERE +++++"
set stat = ./pcx /tmp/kismet_dump $1
# wait for 4 seconds
sleep 4
set count = 'expr $count + 1'
if [ $count -eq 5 ]; then
echo "ERROR: could not open Kismet output pipe."
break
else
if [ $count -ne 1 ]; then
echo "retrying Kismet output pipe..."
else
echo "opening Kismet output pipe..."
fi
fi
done
) # <--- *** ERROR OCCURS HERE, COMPLAINS ABOUT ")" ***
wait
.
.
.It complains about the closing ) after the while loop.
The exact error is:
"./wireless_pcx_shell[33]: [: 0: unexpected operator/operand"
Is there something that I am doing wrong here? Any help would be great, thanks everyone.
Last edited by alc6379; Dec 6th, 2004 at 5:24 pm. Reason: added [code] tags
change:
set count = 'expr $count + 1'
TO:
count = $(( count + 1 ))
This is somewhat cosmetic
You need to check your balanced parents BEFORE the offending line. So far I don't see anything being unbalanced, but doing it with a real editor could be helpful.
set count = 'expr $count + 1'
TO:
count = $(( count + 1 ))
This is somewhat cosmetic
You need to check your balanced parents BEFORE the offending line. So far I don't see anything being unbalanced, but doing it with a real editor could be helpful.
vlad
+-----------------------------------+
| #include <disclaimer.h> |
+-----------------------------------+
+-----------------------------------+
| #include <disclaimer.h> |
+-----------------------------------+
using 'vi':
1. place your cursor on the closing ')' on the offinding line
2. hit '%' - the cursor will move to the MATCHING '(' - make sure it is what it's supposed to be
3. do the same for any preceeding '(' or ')'
1. place your cursor on the closing ')' on the offinding line
2. hit '%' - the cursor will move to the MATCHING '(' - make sure it is what it's supposed to be
3. do the same for any preceeding '(' or ')'
vlad
+-----------------------------------+
| #include <disclaimer.h> |
+-----------------------------------+
+-----------------------------------+
| #include <disclaimer.h> |
+-----------------------------------+
put the whole script in debug:
substitue:
with:
see the script execute - maybe it'll give you a hint.
substitue:
Shell Scripting Syntax (Toggle Plain Text)
#!/bin/ksh
with:
Shell Scripting Syntax (Toggle Plain Text)
#!/bin/ksh set -x
see the script execute - maybe it'll give you a hint.
vlad
+-----------------------------------+
| #include <disclaimer.h> |
+-----------------------------------+
+-----------------------------------+
| #include <disclaimer.h> |
+-----------------------------------+
•
•
Join Date: Dec 2004
Posts: 8
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by vgersh99
put the whole script in debug:
substitue:
Shell Scripting Syntax (Toggle Plain Text)
#!/bin/ksh
with:
Shell Scripting Syntax (Toggle Plain Text)
#!/bin/ksh set -x
see the script execute - maybe it'll give you a hint.
Okay, so I ran it in debug mode, and it got to the kismet_server command, started to run that, then did the cd /home/bang/... command, then the command "[ -gt 0 ]" was run, then it throws the same error (./wireless_pcx_shell[37]: [: 0: unexpected operator/operand) and then does the wait command. I'm not sure why that parentheses is still throwing an error, doesn't seem to make any sense. Any other suggestions? Thanks for helping me...
your culprit is this:
seem that '$stat' does not get assigned any number. When the comparison is made there's nothing to compare against '0'.
instead of using
set count = 0
set stat = 1
use:
typeset -i count = 0
typeset -i stat=1
also, what is the meaning of this?
Shell Scripting Syntax (Toggle Plain Text)
while [ $stat -gt 0 ]
seem that '$stat' does not get assigned any number. When the comparison is made there's nothing to compare against '0'.
instead of using
set count = 0
set stat = 1
use:
typeset -i count = 0
typeset -i stat=1
also, what is the meaning of this?
Shell Scripting Syntax (Toggle Plain Text)
set stat = ./pcx /tmp/kismet_dump $1
vlad
+-----------------------------------+
| #include <disclaimer.h> |
+-----------------------------------+
+-----------------------------------+
| #include <disclaimer.h> |
+-----------------------------------+
•
•
Join Date: Dec 2004
Posts: 8
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by vgersh99
your culprit is this:
Shell Scripting Syntax (Toggle Plain Text)
while [ $stat -gt 0 ]
seem that '$stat' does not get assigned any number. When the comparison is made there's nothing to compare against '0'.
instead of using
set count = 0
set stat = 1
use:
typeset -i count = 0
typeset -i stat=1
also, what is the meaning of this?
Shell Scripting Syntax (Toggle Plain Text)
set stat = ./pcx /tmp/kismet_dump $1
I'm trying to have stat be whether or not the ./pcx ... command was executed or not. Wont it return a 0 if it completes and a non zero value if it throws an error? For some reason I am operating on that assumption. Is there a better way to have my script stay in that loop and keep trying that command until it succeeds or times out?
![]() |
Similar Threads
- IE Syntax Error and Can“t browse some sites (Viruses, Spyware and other Nasties)
Other Threads in the Shell Scripting Forum
- Previous Thread: Bourne / Bash Unix/Linux shell scripting tutorial
- Next Thread: Using find in a bash shell script
| Thread Tools | Search this Thread |





