Re: [SLE] bash script



[James D. Parra]

#!/bin/bash

cd /opt/location
exec filename

Thank you for all of your responses. They all worked perfectly.

Two little comments.

First, "cd /opt/location && exec filename" is a bit better, so if the directory does not exist, the command will not be executed. Only a good habit to take: and this one saved my life a few times! :-)

Second, someone said that "exec" was not needed. This is true. Yet, it is a tiny bit faster to use "exec", because the called program will then _replace_ the shell, and when the program will terminate, that will be the end of the story. Otherwise, without the "exec", when the program will terminate, the shell will have to regain control for nothing else than terminating itself. Nowadays, such optimisations are anachronic!

--
François Pinard http://pinard.progiciels-bpi.ca

--
Check the headers for your unsubscription address
For additional commands send e-mail to suse-linux-e-help@xxxxxxxx
Also check the archives at http://lists.suse.com
Please read the FAQs: suse-linux-e-faq@xxxxxxxx



Relevant Pages

  • Re: Killing a thread/program after calling it
    ... I have to constantly calling a program through "exec", ... This will be called on in a loop inside a script. ... Is there any way that, each time I call program_a.exe, I can let tcl ... twapi.magicsplat.com) has the end_process command to terminate ...
    (comp.lang.tcl)
  • Re: OLE error
    ... It appears that executing WMIC via Exec causes the Exec method to behave ... 'so bail after 10 seconds so we don't hang forever :-) ... 'if you *don't* terminate, the ReadAll hangs... ...
    (microsoft.public.scripting.wsh)
  • Re: Why I need to click twice to destroy a top level window?
    ... 'exec' in TCL does not terminate the current process ... like e.g. in sh or perl. ...
    (comp.lang.tcl)
  • Re: detect shell script language
    ... In the 'old' days, when a user typed in a command, the interactive shell would immediately pass it off to 'exec' to execute. ... So, on return from exec with an error status, the shell would fork a copy of itself to try and run the script. ... As a result of the above, it was hard to tell whether the script was a Bourne shell or C shell, so the convention was introduced of using the Bourne shell no op command, as the first line in a Bourne shell script. ...
    (Debian-User)
  • Re: [SLE] Compiled a C program, cannot run by name
    ... Your current directory is not checked for executables in most ... And why should the DOS shell be derided for providing this ... > I did a man exec and it seems to be a bash script executor, ... When calling "exec ./myapp" the process image of the shell is replaced ...
    (SuSE)