* Martin Kacerovsky <wizard@matfyz.cz> [20030304 13:14 PST]: > Hi, > > On Tue, Mar 04, 2003 at 12:15:56PM -0800, Vineet Kumar wrote: > > * Nori Heikkinen <nori@sccs.swarthmore.edu> [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/3 00:00:00 bash > 9771 pts/3 00:00:00 bash > 9772 pts/3 00:00:00 sleep > 9773 pts/3 00: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/3 00:00:00 bash 9771 pts/3 00:00:00 test.sh 9772 pts/3 00:00:00 sleep 9773 pts/3 00: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/
Attachment:
signature.asc
Description: Digital signature