Unix/Linux Go Back    


UNIX for Beginners Questions & Answers If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

Dumb question on script execution

UNIX for Beginners Questions & Answers


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-13-2017   -   Original Discussion by SIMMS7400
SIMMS7400's Unix or Linux Image
SIMMS7400 SIMMS7400 is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 28 December 2017, 8:19 PM EST
Posts: 153
Thanks: 35
Thanked 3 Times in 3 Posts
Dumb question on script execution

Hi Folks -

I have a dumb question.

Why does this work:



Code:
pushd "/apps/scripts"
./script.sh
popd

But this doesn't:


Code:
./apps/scripts/script.sh

Is it that obvious where I'm overlooking it?

Last edited by SIMMS7400; 12-13-2017 at 05:37 PM..
Sponsored Links
    #2  
Old Unix and Linux 12-13-2017   -   Original Discussion by SIMMS7400
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 19 January 2018, 11:36 AM EST
Location: Aachen, Germany
Posts: 11,958
Thanks: 353
Thanked 3,687 Times in 3,385 Posts
Then "<path to script>" != ./apps/scripts/, I'd say. Check with e.g. ls.
Sponsored Links
    #3  
Old Unix and Linux 12-13-2017   -   Original Discussion by SIMMS7400
SIMMS7400's Unix or Linux Image
SIMMS7400 SIMMS7400 is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 28 December 2017, 8:19 PM EST
Posts: 153
Thanks: 35
Thanked 3 Times in 3 Posts
That's the thing - it's the same path.
    #4  
Old Unix and Linux 12-13-2017   -   Original Discussion by SIMMS7400
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 19 January 2018, 11:51 AM EST
Location: Amsterdam
Posts: 11,707
Thanks: 530
Thanked 3,399 Times in 2,995 Posts
What does not work? What does the script do? A difference is that you are in a different directory. If inside the script you are writing a file to a relative path that might make a difference for example.

Last edited by Scrutinizer; 12-14-2017 at 01:36 AM..
Sponsored Links
    #5  
Old Unix and Linux 12-13-2017   -   Original Discussion by SIMMS7400
SIMMS7400's Unix or Linux Image
SIMMS7400 SIMMS7400 is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 28 December 2017, 8:19 PM EST
Posts: 153
Thanks: 35
Thanked 3 Times in 3 Posts
./apps/scripts/script.sh says does does recognize directory or script name.

But



Code:
pushd "/apps/scripts"
./scripts.sh
popd

works fine. I'm baffled
Sponsored Links
    #6  
Old Unix and Linux 12-13-2017   -   Original Discussion by SIMMS7400
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 19 January 2018, 4:40 AM EST
Location: San Jose, CA, USA
Posts: 10,916
Thanks: 609
Thanked 3,818 Times in 3,262 Posts
Quote:
Originally Posted by SIMMS7400 View Post
./apps/scripts/script.sh says does does recognize directory or script name.

But



Code:
pushd "/apps/scripts"
./scripts.sh
popd

works fine. I'm baffled
Why are you baffled. You have two VERY different paths to process:


Code:
./apps/scripts/script.sh

is a relative pathname. The code:


Code:
pushd "/apps/scripts"
./scripts.sh
popd

is logically equivalent to the absolute pathname:


Code:
/apps/scripts/./scripts.sh

These two paths are equivalent only if you are sitting in the directory / when you use the relative pathname.

And, even if you correctly specify a pathname of a script when invoking it, whether or not it will work depends on whether or not that script uses any relative pathnames when referencing files it wants to open. If you invoke the script with:


Code:
/apps/scripts/./scripts.sh

or, more simply,


Code:
/apps/scripts/scripts.sh

any relative pathname references scripts.sh makes will be relative to the directory you are sitting in when you invoke scripts.sh.
But, if you invoke the script with:


Code:
pushd "/apps/scripts"
./scripts.sh
popd

any relative pathname references scripts.sh makes will be relative to the directory /apps/scripts.
Sponsored Links
    #7  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by SIMMS7400
SIMMS7400's Unix or Linux Image
SIMMS7400 SIMMS7400 is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 28 December 2017, 8:19 PM EST
Posts: 153
Thanks: 35
Thanked 3 Times in 3 Posts
Don -

That makes perfect sense. Thank you for the explanation!!!
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
this is a very dumb question...i know... :( cromohawk UNIX for Dummies Questions & Answers 1 02-18-2009 09:12 PM
Another dumb question but... KGee UNIX for Dummies Questions & Answers 2 01-15-2009 10:42 AM
Another dumb question... JayC89 UNIX for Dummies Questions & Answers 1 01-28-2008 08:29 PM
script dumb question piltrafa UNIX for Dummies Questions & Answers 6 08-02-2005 12:30 PM
dumb question madhab99 UNIX for Dummies Questions & Answers 1 12-20-2000 07:41 PM



All times are GMT -4. The time now is 05:06 PM.