Reputation: 47
I have a simple script (x.sh):
echo $$
sleep 60
when I run this and "ps -ef | grep x.sh" I get nothing back. Running "ps -ef | grep " I get:
jsm_adm+ 7695 5700 0 12:25 pts/0 00:00:00 -bash
jsm_adm+ 7696 7695 0 12:25 pts/0 00:00:00 sleep 60
jsm_adm+ 7698 5841 0 12:25 pts/1 00:00:00 grep --color=auto 7695
If I add "#!/bin/bash" as the first line x.sh then I get get:
jsm_adm+ 7693 5700 0 12:25 pts/0 00:00:00 /bin/bash ./x.sh
jsm_adm+ 7694 7693 0 12:25 pts/0 00:00:00 sleep 60
jsm_adm+ 7701 5841 0 12:25 pts/1 00:00:00 grep --color=auto 7693
Is there a way I can find that "x.sh" is running if the user hasn't put a hashbang as the first line of their script? Also, what does "-bash" mean in this context?
Upvotes: 0
Views: 371
Reputation: 1746
Because you do not have a bash
script in this x.sh
file. The problem is exactly the hashtag #!/bin/bash
you describe. If you do not put it into your file bash
does not interpret your file as bash script. If you want to know more you could navigate to this guide and have a look.
What occurs in your case is without the hashtag both command are interpreted as if you were typing them directly in the shell which you could observe in your first ps
output as you see the program sleep(60)
.
Upvotes: 1