Mailinglist Archive: opensuse (1503 mails)

< Previous Next >
Re: [opensuse] umm BASH gurus, what does the typo $!/bin/bash do?
  • From: "Brian K. White" <brian@xxxxxxxxx>
  • Date: Fri, 02 Oct 2009 04:26:05 -0400
  • Message-id: <4AC5B91D.10705@xxxxxxxxx>


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@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >
This Thread
Follow Ups
References