You prefix sh when you want a specific shell to be used to interpret the script and not the current shell of the current user, no matter if interactive or as crontab entry.
Thank You Cero.
So, If I use shebang ( #!/bin/bash as the first line) in the script itself, I don't need to place sh before the script name to execute it.Right ?
Both are valid ways of doing it. Look at a (properly written) scripts beginning and you will usually see:
This requests the system to first load /path/to/interpreter and then feed it the rest of the script as input. If your first line is #! /path/to/bash this interpreter will be bash and hence your script will be executed as bash-shellscript.
Every shell (make that: every shell i know of) also has the ability to accept a parameter on the command line, which denotes a list of commands which wll be in turn executed by the shell you have called:
will load /path/to/bash into memory and then - instead of initiating an interactive session - execute what is in /some/file one line after the other. (In principle there is no difference between scripts and commands entered at the commandline, a "script" is in fact just a list of commands in a file.)
The only difference between the two variants:
is that in the second variant /some/script.file has to have the executable-flag set in order to be executed:
in the first variant it is not necessary to have the x-flag set and in the above this:
will be processed as well. Therefore using this in crontab will allow you to execute something as script without having its x-flag set.
I leave it to you to decide if this is a desirable state of affairs. Personally i think it is not, but then, i have a certain way of doing things and you might come to different conclusions. There are more than one ways to skin a cat.
Basically there is no need to prefix the script with a shell - if you leave it out, your current shell will be used. But different shells use different syntax. So naming which shell to use ensures that the script is interpreted by the shell it was written for.
A shebang in a script does more or less the same what "prefixing" does: invoce the shell with the scriptname (+ arguments) as argument, so prefixing is not needed.
I am from MQ/MB technology. My requirement is to display the queue manger and broker status on daily basis.
If I manually run the script, it works fine and displays output. But when I have scheduled the same using cronjobs it shows only the queue manger status and not the broker status.
Can... (3 Replies)
Hi
I was wondering if there was any command with autorep that can be used to check what the jobname is by givin scriptname that is defined in the JIL of the job (1 Reply)
Hi,
I am using solaris 10.Is there any way to execute the script with the scriptname wihtoug using ./scriptname?Also does it varies from shell to shell.I have scripts in bash,ksh,sh shells.
Example:script.sh is the script name.I need to execute the script like this script.sh instead... (4 Replies)
I am going to run the scripts (filetest.sh)
Its run with.....
./filetest.sh
sh filetest.sh
but not run with.....
filetest.sh ( giviing error command not found)
tell me the way how we can do it ? (6 Replies)
I have started to write Korn scripts on the client's AIX 4.2 servers and there is this small problem that puzzles me.
I code all my scripts the same way:
- first line contains :
#!/bin/ksh
- I do this console command on every scripts:
chmod +x scriptname
But still, on some occasions,... (4 Replies)
I have simply downloaded a file to my local folder, made one small change and uploaded it back, ever since it will not run the file.
I have now uploaded the original, unchanged file, which still doesn;t work.
Evertime it is run ot says bash: ./nrcardprint: No such file or directory
The... (10 Replies)
Hi everyone,
I'm very new, I just wrote a script "Hello World" :) LOL
How can I execute the script without the ./myscript.
I want to just type "myscript" basically from anywhere without the " ./ ".
Thanks a bunch,
NinjaX (2 Replies)
I have several crontab scripts running which email me status. Some of these scripts perform identical tasks so I get a similar emails sent to myself.
How do I get the script to print it's own path/filename so I can include it in the status updates without hardcoding trhe filename into the... (1 Reply)