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

👤 Login to reply
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-13-2017
SIMMS7400 SIMMS7400 is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 17 July 2018, 6:46 AM EDT
Posts: 159
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 04:37 PM..
Sponsored Links
    #2  
Old 12-13-2017
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 18 July 2018, 6:40 AM EDT
Location: Aachen, Germany
Posts: 13,070
Thanks: 449
Thanked 4,013 Times in 3,690 Posts
Then "<path to script>" != ./apps/scripts/, I'd say. Check with e.g. ls.
Sponsored Links
    #3  
Old 12-13-2017
SIMMS7400 SIMMS7400 is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 17 July 2018, 6:46 AM EDT
Posts: 159
Thanks: 35
Thanked 3 Times in 3 Posts
That's the thing - it's the same path.
    #4  
Old 12-13-2017
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 18 July 2018, 7:48 AM EDT
Location: Amsterdam
Posts: 11,853
Thanks: 546
Thanked 3,469 Times in 3,057 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 12:36 AM..
Sponsored Links
    #5  
Old 12-13-2017
SIMMS7400 SIMMS7400 is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 17 July 2018, 6:46 AM EDT
Posts: 159
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 12-13-2017
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 18 July 2018, 7:28 AM EDT
Location: San Jose, CA, USA
Posts: 11,407
Thanks: 649
Thanked 3,970 Times in 3,393 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 12-19-2017
SIMMS7400 SIMMS7400 is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 17 July 2018, 6:46 AM EDT
Posts: 159
Thanks: 35
Thanked 3 Times in 3 Posts
Don -

That makes perfect sense. Thank you for the explanation!!!
Sponsored Links
👤 Login to reply

« Previous Thread | Next Thread »
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
this is a very dumb question...i know... :( cromohawk UNIX for Dummies Questions & Answers 1 02-18-2009 08:12 PM
Another dumb question but... KGee UNIX for Dummies Questions & Answers 2 01-15-2009 09:42 AM
Another dumb question... JayC89 UNIX for Dummies Questions & Answers 1 01-28-2008 07:29 PM
script dumb question piltrafa UNIX for Dummies Questions & Answers 6 08-02-2005 11:30 AM
dumb question madhab99 UNIX for Dummies Questions & Answers 1 12-20-2000 06:41 PM



All times are GMT -4. The time now is 08:30 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?