Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-30-2012
Registered User
 
Join Date: Dec 2011
Location: Chennai, India
Posts: 115
Thanks: 40
Thanked 1 Time in 1 Post
Basic question on shell script execution

I have two shell scripts in the different directories listed below,


Code:
/root/dev/dir1/test.sh
/root/dev/dir2/master.sh

I am executing the master.sh script from the test.sh like below and getting 'Permission denied' error.


Code:
#! /bin/sh
#test.sh
path='/root/dev'
$path/dir2/master.sh

But it works fine after including a '.' infront of the script and it works fine. Please see below for the change,


Code:
#! /bin/sh
#test.sh
path='/root/dev'
. $path/dir2/master.sh

Please explain the concept behind this and let me know is there any way to execute the master.sh in dir2 without the '.' symbol
Sponsored Links
    #2  
Old 07-30-2012
Scott's Avatar
Scott Scott is online now Forum Staff  
Administrator
 
Join Date: Jun 2009
Location: Zürich
Posts: 6,854
Thanks: 212
Thanked 745 Times in 651 Posts
What are the permissions on the dir2/master.sh script? Is it executable?

By using . (dot) you are "sourcing" the script into your current environment, and it's run from there. If you want to run it the way you have, it needs to be executable.
The Following User Says Thank You to Scott For This Useful Post:
vel4ever (07-30-2012)
Sponsored Links
    #3  
Old 07-30-2012
Registered User
 
Join Date: Dec 2011
Location: Chennai, India
Posts: 115
Thanks: 40
Thanked 1 Time in 1 Post
I have added the below code piece and found the file is not executable


Code:
if [ -x $path/dir2/master.sh ]
then
echo "Executable"
else
echo "Not executable"
fi

---------- Post updated at 04:55 AM ---------- Previous update was at 04:39 AM ----------

Thank you Scott. I wasn't facing this problem earlier and my profile has been reset. I guess this is the root cause.
Sponsored Links
Closed Thread

Tags
shell bash

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Question about a basic shell script: How to make sure it receives only one input? 2358 Shell Programming and Scripting 3 11-29-2011 02:48 AM
Basic shell script help kylecn Shell Programming and Scripting 7 06-16-2011 10:25 PM
Basic Shell Script Help c4391 Shell Programming and Scripting 1 03-24-2010 01:35 AM
Basic script question suphawk Shell Programming and Scripting 4 01-21-2010 12:31 PM
basic shell scripting question convenientstore Shell Programming and Scripting 3 05-27-2007 10:21 PM



All times are GMT -4. The time now is 12:35 AM.