How can I list running bash scripts by the name of the script?

The problem here is that ps by default only shows the base command in its output, not the whole command line including arguments.

If you launch your script with bash TestEric.sh, the base command is bash. If you run it as TestEric.sh (possibly including its path), the base command will be that and not bash.


You can easily use pgrep instead of ps to list processes filtered by name. It has a -f flag that makes it match the given pattern against the whole command line instead of just the base command.

The -a flag makes it display that whole command line in its output for debugging purposes instead of just the PID. Once you verified it works, you can/should remove it again in your script.

Try this:

pgrep -f -a TestEric.sh

You can later count the processes using wc by counting the pgrep output lines:

pgrep -f TestEric.sh | wc -l

You could try running ps u instead. From the man pages, the u option corresponds to display user-oriented format which will display both the shell used to run the script and the name of the script itself.