"ps -ef" using in backquotes
Hi,
I have a question about using the ps within backqoutes (``) When I tried to write a script which is supposed to run just once at a time I encountered the following thing which I don't know if it's a BUG or FEATURE. inside the script 'runonce.sh': ---begin script--- #! /bin/bash # just run the ps and watch te output ps -ef | grep 'runonce.sh' RESULT_FULL=`ps -ef | grep 'runonce.sh'` echo result_full: "$RESULT_FULL" ---end script--- this script outputs: [hostnix] ./runonce.sh oracle 6443 3691 0 15:29:02 pts/8 0:00 /bin/bash ./runonce.sh result_full: oracle 6462 6443 0 15:29:02 pts/8 0:00 /bin/bash ./runonce.sh oracle 6443 3691 0 15:29:02 pts/8 0:00 /bin/bash ./runonce.sh oracle 6464 6462 0 15:29:02 pts/8 0:00 grep runonce.sh why do I get the /bin/bash ./runonce.sh twice ?? any help welcome guenter porzer |
You're running the ps twice, that's why you're seeing it twice.
|
hi,
actually the ps is not running twice at the same time. It gets started in consecutive. Besides what I don't understand is why in $RESULT_FULL I'm getting the runonce.sh script twice ? If I run the same script in KSH( just changing #!/bin/bash to #!/bin/ksh ) I'm geting the expected result of 1 script process and 1 grep process. As you can see in BASH I'm getting 3 processes 2 scripts running and 1 grep. thanks guenter porzer |
If you want to know whats happening, add -x to /bin/bash.
Code:
#!/bin/bash -x |
Are you asking why you see "/bin/bash" and "grep" lines? The grep line is the result of your script. You might try the "grep -v grep" trick or grep for [r]unonce.sh.
|
The OP is certainly asking why these two lines appears for a single script:
Code:
oracle 6462 6443 0 15:29:02 pts/8 0:00 /bin/bash ./runonce.sh |
@ jlliagre, you are absolute right.
In the meantime I found a workaround for this behavior. I just thougt there would be no difference between ksh and bash concerning backquotes ( or at least I've never read anything about this ). Anyway thanks for all input for this topic ! guenter porzer |
All times are GMT -5. The time now is 07:37 PM. |