Home Man
Search
Today's Posts
Register

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
# 1  
Old 12-13-2017
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..
# 2  
Old 12-13-2017
Then "<path to script>" != ./apps/scripts/, I'd say. Check with e.g. ls.
# 3  
Old 12-13-2017
That's the thing - it's the same path.
# 4  
Old 12-13-2017
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..
# 5  
Old 12-13-2017
./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
# 6  
Old 12-13-2017
Quote:
Originally Posted by SIMMS7400
./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.
# 7  
Old 12-19-2017
Don -

That makes perfect sense. Thank you for the explanation!!!
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
really dumb MV command question ideal2545 UNIX for Dummies Questions & Answers 4 04-20-2012 05:15 PM
Help with dumb for-loop question amithkhandakar Shell Programming and Scripting 3 12-18-2011 03:34 PM
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
got a dumb question where do i get AIX 5.3 from wmccull AIX 2 09-04-2007 12:01 PM
Ok really dumb question but... Corrail UNIX for Dummies Questions & Answers 3 11-22-2005 08:00 PM
script dumb question piltrafa UNIX for Dummies Questions & Answers 6 08-02-2005 11:30 AM
really dumb question... justchillin UNIX for Dummies Questions & Answers 3 08-06-2001 12:02 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 03:20 PM.

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