[opensuse] umm BASH gurus, what does the typo $!/bin/bash do?
Guys, This was bizarre. Doing a quick script, I accidentally did a $!/bin/bash instead of #!/bin/bash. The script gave no output, but appeared to be struggling much longer than it should (~1 sec) then would exit normally. No error no nothing. Something worked though. I had set a trap to remove a temp dir in it and provide output. When I ssh'ed into another box and came back, evidently the EXIT signal was generated and the trap ran -- even though it the script defined $! instead of #!. Can anybody tell me, or point me to any info, concerning just what $! did?? -- David C. Rankin, J.D.,P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
David C. Rankin wrote:
Guys,
This was bizarre. Doing a quick script, I accidentally did a $!/bin/bash instead of #!/bin/bash. The script gave no output, but appeared to be struggling much longer than it should (~1 sec) then would exit normally. No error no nothing. Something worked though. I had set a trap to remove a temp dir in it and provide output. When I ssh'ed into another box and came back, evidently the EXIT signal was generated and the trap ran -- even though it the script defined $! instead of #!.
Can anybody tell me, or point me to any info, concerning just what $! did??
Larry Wall 'splains it all... http://tldp.org/LDP/abs/html/sha-bang.html (lower part) You don't actually need the #! in a bash script if bash is your default shell. So it was probably trying to figure out what $ meant. Then it saw the !. When you type a word preceeded by an "!", bash thinks you want to recall a previous command or "event". It happens in interactive shells, when the C-Shell-styled history expansion (”!searchword”) is enabled. This is the default. Then it probably recovered and just continued. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
David C. Rankin wrote:
Guys,
This was bizarre. Doing a quick script, I accidentally did a $!/bin/bash instead of #!/bin/bash. The script gave no output, but appeared to be struggling much longer than it should (~1 sec) then would exit normally. No error no nothing. Something worked though. I had set a trap to remove a temp dir in it and provide output. When I ssh'ed into another box and came back, evidently the EXIT signal was generated and the trap ran -- even though it the script defined $! instead of #!.
Can anybody tell me, or point me to any info, concerning just what $! did?
My guess is simply that $! expands to nothing, so effectively the line is just "/bin/bash" Since the first chars of the first line were not #! then there was nothing special about the first line. It was the same as if you had nothing on the first line and had just /bin/bash on some lower line. I leave it to you to contemplate what that would be like. You'd get a prompt exactly like the one you were on before running the script. So, you'd think the script exited, but no you were still in the script, still busy executing the first line, /bin/bash, until you typed exit or hit ctrl-d, (/bin/bash finishes), at that point the rest of the script would run. -- bkw -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Friday 02 October 2009 03:26:05 am Brian K. White wrote:
So, you'd think the script exited, but no you were still in the script, still busy executing the first line, /bin/bash, until you typed exit or hit ctrl-d, (/bin/bash finishes), at that point the rest of the script would run.
Yah, but you out to have seen all the output when I typed strace ./scriptname :p -- David C. Rankin, J.D.,P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (3)
-
Brian K. White
-
David C. Rankin
-
John Andersen