Click to See Complete Forum and Search --> : Bash: Bogus Syntax Error?
Sepero
03-29-2003, 08:29 AM
Ok, I've narrowed my problem down to one line of code. (Don't you wish everybody would do that? :))
The code:
for t1 in `ps -x` ; do
This is the error I get:
Bad syntax, perhaps a bogus "-"?
What is my problem?!?! I'm almost 100% sure it has to do with the "-x" part because "for t1 in `ls -l` ; do" works just fine.
Help :p
chrism01
03-29-2003, 04:02 PM
Try this:
for t1 in `ps -x`
do
<your code here>
done
drop the ';'.
Sepero
03-29-2003, 05:33 PM
Originally posted by chrism01
Try this:
for t1 in `ps -x`
do
<your code here>
done
drop the ';'.
I tried it...
Still not working. :)
Thanks for trying though. I really believe that Bash is trying to interperet the "-x" differently than the way I need it to run.
I tried using $(ps -x) and "`ps -x`". All giving me the ' Bogus "-"? ' error.
Any other suggestions?
(It seems like no matter what programming language I try, when I first get started, there are advanced topics that just seem to 'leap' into my code. Baffling me for days. Ahhhh... the love of programming :p )
chrism01
03-29-2003, 06:16 PM
Interesting; i just tried my suggestion using
echo $t1
in the <your code here> bit and it worked just fine. I'm on RH7.2 Possibly your distro doesn't support the '-x' switch? Have you checked the man page for ps ?
Sepero
03-29-2003, 06:35 PM
Originally posted by chrism01
Interesting; i just tried my suggestion using
echo $t1
in the <your code here> bit and it worked just fine. I'm on RH7.2 Possibly your distro doesn't support the '-x' switch? Have you checked the man page for ps ?
Thanks chrism01. I just found out I get the exact same error when I type "ps -x" on the command line!
Apparently, I need to type just "ps x". Maybe this is only in the Slackware version of ps. Anyway, thanks again. :D
Haleluya! Free at last!
bwkaz
03-29-2003, 07:05 PM
My ps manpage says:
This version of ps accepts several kinds of options.
Unix98 options may be grouped and must be preceeded by a dash.
BSD options may be grouped and must not be used with a dash. And it continues, talking about GNU long options (they're preceded by two dashes). So it sounds like your version of ps doesn't take Unix98 options, just BSD options. At least, as far as the x option is concerned.
Sepero
03-29-2003, 07:57 PM
To bwkaz:
Cool, thanks for the info. Actually, the whole thing seems kinda retarded. :p You'd think that ps would respond to "-" like every other program on unix. Oh well, you learn somethin new everyday.
PS.
Please don't anyone get on my case for not being able to use ps. Before I always used top instead. ;) heheh
chrism01
03-30-2003, 08:45 AM
That's what makes it tricky giving advice on "Linux". Sometimes different distros do it differently and what works perfectly on one uses a facility/option etc that doesn't exist on another or is implemented differently.
;)
Glad we got there in the end. :)