Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-23-2010, 12:49 AM   #1
LQ Newbie
Registered: Apr 2010
Location: Hyderabad
Distribution: Suse Linux
Posts: 1

Rep: Reputation: 0
Unhappy 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,
Old 04-23-2010, 01:20 AM   #2
Senior Member
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107

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.
Old 06-07-2011, 08:58 PM   #3
Registered: May 2006
Location: Brisbane, Australia
Distribution: linux
Posts: 157

Rep: Reputation: 44
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem executing mv command inside shell script pablogosse Linux - General 7 12-16-2009 01:21 PM
Runs Multiple shell script inside a main script using crontab srimal Linux - Newbie 4 10-22-2009 07:19 PM
Shell script inside shell script treotan Linux - General 4 02-19-2009 07:34 AM
Executing a shell script command!! vishamr2000 Programming 4 08-15-2005 01:33 AM
executing a shell script from C llama_meme Programming 2 04-01-2002 10:10 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:10 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration