-   Linux - Newbie (
-   -   Executing a Shell script with 654 permissions inside another shell script. (

changusee2k 04-23-2010 12:49 AM

Executing a Shell script with 654 permissions inside another shell script.
Hi All,

I have this scenario, where in I'm calling a shell script inside another shell script. The only criteria here is that the embedded script will have 654 permissions and the master script should be able to execute this embedded script. Please advise as to how this can be done? The sample code is given below:



${bindir}/test.ksh -d ${dblogin} -i ${datadir} -r ${filedt} > ${tmp_log}

The test.ksh which has 654 permissions is called by the main.ksh script and when i try to run it using ./main.ksh, it fails with the error "Execute permissions denied."

A quick response as to how this can be resolved will be greatly appreciated.

Thanks in advance,

vikas027 04-23-2010 01:20 AM

you can execute any script with giving the name of the shell before it.

For. e.g.

Now, even if your script has 644 (or 654), it can be run smoothly

Hope this helps.

A.Thyssen 06-07-2011 08:58 PM

The only reason you may not execute the script directly due to permissions is that it does not have execute for the current running UID and GID of the user/process.
With permissions 654 that means only someone in the same group as the script BUT is not the owner of the script can 'execute' it.

A script however also requires you have read access, so the running 'interpreter' regardless of if that is a shell, perl, or other program, can also read the file to execute it.

In older UNIX's a unreadable shell script was possible by using permissions 4711.
That is it is executable by anyone, but Set-UID's to the owner of the script, which provides read permission. However I believe Set-UID scripts are not permitted under Linux.


Okay. NONE of this however matters if you run the interpreter yourself! Just as forum user "vikas027" pointed out. That is you run the script using a command like

bash script_filename
awk -f script_filename

In this case the script is being treated a just a plain file that is read by the interpretor command. Only read permission is required in this case, as such the script could have permissions of just 444 (read only to everyone, including owner) for it to work (unless the script modifies itself! Weird, but I have see it done!)


There is however one other situation for things like shell script. Source scripts.
that is you don't want the shell to run the script as a sub-process, by launching a new interpretor, but by having the currently running shell interpret it. In some languages this is also known as an 'include'.

A source shell is typically requires if you want that script to modify the current environment (and not a sub-shells environment that then gets deleted). For example to change the current directory (working directory), or set environment variables (like PATH), or local shell variables (like the prompt).

In such a case teh script is typically not made executable, and it is also a good idea to give the script a fake interpretor, that just generates an appropriate error. For example


#!/bin/echo "Source Script Only -- Do not execute -- ABORTING"
# Setup software package to working environment

All times are GMT -5. The time now is 05:33 PM.