Re: commands within shell script
on Wed, 05 Mar 2003 07:49:52AM -0600, Ron Johnson insinuated: > On Tue, 2003-03-04 at 20:41, Nori Heikkinen wrote: > > on Tue, 04 Mar 2003 05:13:33PM -0500, Benjamin Rutt insinuated: > > > Nori Heikkinen <[EMAIL PROTECTED]> writes: > > > > okay, this is cool ... i'd just misunderstood a friend's question. > > > > he doesn't even want to run top, he wants to stick in a bunch of > > > > echo statements. > > > > > > In that case, place 'set -x' as the 2nd line of the shell script > > > (the line after the #! business) and see every command echoed as it > > > is executed. -- Benjamin > > > > *exactly* what i(/he) wanted! thanks! > > Try this: > #!/bin/bash > set -x > set -v > for i in 1 2 3 4 5; > do > echo foobar${i} ; > done > > After seeing Benjamin Rutt mention "-x", I tried it along with "-v", > and having both makes it much easier to see the flow of the script. well, it's cluttered for me, but both are cool options. thanks again, -- .~. nori @ sccs.swarthmore.edu /V\ http://www.sccs.swarthmore.edu/~nori/jnl/ // \\ @ maenad.net /( )\ www.maenad.net ^`~'^ -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: commands within shell script
On Tue, 2003-03-04 at 20:41, Nori Heikkinen wrote: > on Tue, 04 Mar 2003 05:13:33PM -0500, Benjamin Rutt insinuated: > > Nori Heikkinen <[EMAIL PROTECTED]> writes: > > > okay, this is cool ... i'd just misunderstood a friend's question. > > > he doesn't even want to run top, he wants to stick in a bunch of > > > echo statements. > > > > In that case, place 'set -x' as the 2nd line of the shell script > > (the line after the #! business) and see every command echoed as it > > is executed. -- Benjamin > > *exactly* what i(/he) wanted! thanks! Try this: #!/bin/bash set -x set -v for i in 1 2 3 4 5; do echo foobar${i} ; done After seeing Benjamin Rutt mention "-x", I tried it along with "-v", and having both makes it much easier to see the flow of the script. -- +---+ | Ron Johnson, Jr. Home: [EMAIL PROTECTED] | | Jefferson, LA USA http://members.cox.net/ron.l.johnson | | | | The difference between Rock&Roll and Country Music? | | Old Rockers still on tour are pathetic, but old Country | | signers are still great. | +---+ -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: commands within shell script
on Tue, 04 Mar 2003 05:13:33PM -0500, Benjamin Rutt insinuated: > Nori Heikkinen <[EMAIL PROTECTED]> writes: > > okay, this is cool ... i'd just misunderstood a friend's question. > > he doesn't even want to run top, he wants to stick in a bunch of > > echo statements. > > In that case, place 'set -x' as the 2nd line of the shell script > (the line after the #! business) and see every command echoed as it > is executed. -- Benjamin *exactly* what i(/he) wanted! thanks! -- .~. nori @ sccs.swarthmore.edu /V\ http://www.sccs.swarthmore.edu/~nori/jnl/ // \\ @ maenad.net /( )\ www.maenad.net ^`~'^ -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: commands within shell script
Hi, On Tue, Mar 04, 2003 at 02:32:40PM -0800, Vineet Kumar wrote: > > This is all consistent with what I've said. > sleep is a process, not a builtin, Yeah, I see, I had overlooked that 'built-in', that explains it. > and shows up in the process list. So, too, does the bash which > is spawned to execute the shell script. > > I guess you're wondering why the script name doesn't show up > like I said it would. Try it with a '#!/bin/bash', Yeah, it works, I haven't know that without it, the shell won't "get the name of the script" in 'ps' output > You should always start your scripts with a shebang, otherwise they're > really just text files that your shell has to guess what to do with. Yes, I do it everytimes, but I just wanted to put it as short as possible, and with that 'echo >' it was the shortest way how to write the test.sh script. > good times, > Vineet Good times to you. Bye. -- +--+ | Martin Kacerovsky| | e-mail : wizard(AT)matfyz(DOT)cz | | home : http://wizard.matfyz.cz | +--+ pgp0.pgp Description: PGP signature
Re: commands within shell script
* Martin Kacerovsky <[EMAIL PROTECTED]> [20030304 13:14 PST]: > Hi, > > On Tue, Mar 04, 2003 at 12:15:56PM -0800, Vineet Kumar wrote: > > * Nori Heikkinen <[EMAIL PROTECTED]> [20030304 12:11 PST]: > > > hey, > > > > > > by default, a shell script just appears as the script name in a list > > > of processes (ps; top), right? how can i make it show each command > > > called within the script as it's being executed? > > > > It already is. For each program called from the script, > > the shell forks and execs a new process, which shows up in the > > process list. Of course, you won't see shell builtin commands > > in the process list, just the shell name and script name. > > But see this, I don't understand: > > ( ~ )$ > ( ~ )$ echo 'sleep 10' > test.sh > ( ~ )$ chmod +x test.sh > ( ~ )$ ./test.sh & > [1] 9771 > ( ~ )$ ps > PID TTY TIME CMD > 26101 pts/300:00:00 bash > 9771 pts/300:00:00 bash > 9772 pts/300:00:00 sleep > 9773 pts/300:00:00 ps > ( ~ )$ > ( ~ )$ > [1]+ Done./test.sh > ( ~ )$ > > and If I had run it in background, then on another terminal, I saw > in 'ps -A' the bash and sleep processes too. This is all consistent with what I've said. sleep is a process, not a builtin, and shows up in the process list. So, too, does the bash which is spawned to execute the shell script. I guess you're wondering why the script name doesn't show up like I said it would. Try it with a '#!/bin/bash', in which case your process listing would instead like like this: PID TTY TIME CMD 26101 pts/300:00:00 bash 9771 pts/300:00:00 test.sh 9772 pts/300:00:00 sleep 9773 pts/300:00:00 ps You should always start your scripts with a shebang, otherwise they're really just text files that your shell has to guess what to do with. Although it usually gets it right, it might not sometimes; it might be a bash- csh- ksh- or zsh-specific script, instead of being able to execute with vanilla sh. good times, Vineet -- http://www.doorstop.net/ -- http://www.eff.org/ signature.asc Description: Digital signature
Re: commands within shell script
Nori Heikkinen <[EMAIL PROTECTED]> writes: > okay, this is cool ... i'd just misunderstood a friend's question. he > doesn't even want to run top, he wants to stick in a bunch of echo > statements. In that case, place 'set -x' as the 2nd line of the shell script (the line after the #! business) and see every command echoed as it is executed. -- Benjamin -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: commands within shell script
On Tue, 2003-03-04 at 13:47, Nori Heikkinen wrote: > hey, > > by default, a shell script just appears as the script name in a list > of processes (ps; top), right? how can i make it show each command > called within the script as it's being executed? Maybe you are talking about this: #!/bin/bash -v for i in 1 2 3 4 5; do echo foobar${i} ; done echo $HOME ; echo $LANG The "-v" makes it happen. -- +---+ | Ron Johnson, Jr. Home: [EMAIL PROTECTED] | | Jefferson, LA USA http://members.cox.net/ron.l.johnson | | | | The difference between Rock&Roll and Country Music? | | Old Rockers still on tour are pathetic, but old Country | | signers are still great. | +---+ -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: commands within shell script
on Tue, 04 Mar 2003 09:20:27PM +0100, Martin Kacerovsky insinuated: > On Tue, Mar 04, 2003 at 02:47:49PM -0500, Nori Heikkinen wrote: > > by default, a shell script just appears as the script name in a > > list of processes (ps; top), right? how can i make it show each > > command called within the script as it's being executed? > > I don't think so, name of the script is not shown in ps, because > script is only the input file a new shell you execute. And the > commands it runns (e.g. who, ...) are properly displayed. > > Try it. put into file 'test.sh' line 'sleep 10' then chmod +x on > it, and then execute it, in output you will see : the new shell, and > sleep ... okay, this is cool ... i'd just misunderstood a friend's question. he doesn't even want to run top, he wants to stick in a bunch of echo statements. thanks! -- .~. nori @ sccs.swarthmore.edu /V\ http://www.sccs.swarthmore.edu/~nori/jnl/ // \\ @ maenad.net /( )\ www.maenad.net ^`~'^ -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: commands within shell script
Hi, On Tue, Mar 04, 2003 at 12:15:56PM -0800, Vineet Kumar wrote: > * Nori Heikkinen <[EMAIL PROTECTED]> [20030304 12:11 PST]: > > hey, > > > > by default, a shell script just appears as the script name in a list > > of processes (ps; top), right? how can i make it show each command > > called within the script as it's being executed? > > It already is. For each program called from the script, > the shell forks and execs a new process, which shows up in the > process list. Of course, you won't see shell builtin commands > in the process list, just the shell name and script name. But see this, I don't understand: ( ~ )$ ( ~ )$ echo 'sleep 10' > test.sh ( ~ )$ chmod +x test.sh ( ~ )$ ./test.sh & [1] 9771 ( ~ )$ ps PID TTY TIME CMD 26101 pts/300:00:00 bash 9771 pts/300:00:00 bash 9772 pts/300:00:00 sleep 9773 pts/300:00:00 ps ( ~ )$ ( ~ )$ [1]+ Done./test.sh ( ~ )$ and If I had run it in background, then on another terminal, I saw in 'ps -A' the bash and sleep processes too. -- +--+ | Martin Kacerovsky| | e-mail : wizard(AT)matfyz(DOT)cz | | home : http://wizard.matfyz.cz | +--+ pgp0.pgp Description: PGP signature
Re: commands within shell script
Hi, sorry for replying on my own mail On Tue, Mar 04, 2003 at 09:20:27PM +0100, Martin Kacerovsky wrote: > Hi, > > Try it. > put into file 'test.sh' line 'sleep 10' > then chmod +x on it, and then execute it, > in output you will see : the new shell, and sleep ... There should be : in output of 'ps' command ... > Bye. -- +--+ | Martin Kacerovsky| | e-mail : wizard(AT)matfyz(DOT)cz | | home : http://wizard.matfyz.cz | +--+ pgp0.pgp Description: PGP signature
Re: commands within shell script
Hi, On Tue, Mar 04, 2003 at 02:47:49PM -0500, Nori Heikkinen wrote: > hey, > > by default, a shell script just appears as the script name in a list > of processes (ps; top), right? how can i make it show each command > called within the script as it's being executed? I don't think so, name of the script is not shown in ps, because script is only the input file a new shell you execute. And the commands it runns (e.g. who, ...) are properly displayed. Try it. put into file 'test.sh' line 'sleep 10' then chmod +x on it, and then execute it, in output you will see : the new shell, and sleep ... Bye. -- +--+ | Martin Kacerovsky| | e-mail : wizard(AT)matfyz(DOT)cz | | home : http://wizard.matfyz.cz | +--+ pgp0.pgp Description: PGP signature
Re: commands within shell script
* Nori Heikkinen <[EMAIL PROTECTED]> [20030304 12:11 PST]: > hey, > > by default, a shell script just appears as the script name in a list > of processes (ps; top), right? how can i make it show each command > called within the script as it's being executed? It already is. For each program called from the script, the shell forks and execs a new process, which shows up in the process list. Of course, you won't see shell builtin commands in the process list, just the shell name and script name. good times, Vineet -- http://www.doorstop.net/ -- "Those who desire to give up freedom in order to gain security will not have, nor do they deserve, either one." --President Thomas Jefferson signature.asc Description: Digital signature
commands within shell script
hey, by default, a shell script just appears as the script name in a list of processes (ps; top), right? how can i make it show each command called within the script as it's being executed? thanks, -- .~. nori @ sccs.swarthmore.edu /V\ http://www.sccs.swarthmore.edu/~nori/jnl/ // \\ @ maenad.net /( )\ www.maenad.net ^`~'^ -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]