Dumb question on script execution

 
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 05: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 01: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!!!

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Dumb question on the ping command soleblazer UNIX for Dummies Questions & Answers 2 06-27-2014 05:47 PM
really dumb MV command question ideal2545 UNIX for Dummies Questions & Answers 4 04-20-2012 06:15 PM
Help with dumb for-loop question amithkhandakar Shell Programming and Scripting 3 12-18-2011 04:34 PM
My first post (Probably a really dumb php question) gmcpheden Programming 2 06-12-2011 08:03 PM
Dumb find question markdjones82 UNIX for Dummies Questions & Answers 1 04-01-2010 11:32 AM
Dumb gnome terminal question. nixnoob UNIX for Dummies Questions & Answers 3 07-22-2009 04:52 PM
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
got a dumb question where do i get AIX 5.3 from wmccull AIX 2 09-04-2007 01:01 PM
Dumb question but its driving me nuts jepombar UNIX for Dummies Questions & Answers 3 07-03-2007 03:32 PM
Ok really dumb question but... Corrail UNIX for Dummies Questions & Answers 3 11-22-2005 09:00 PM
script dumb question piltrafa UNIX for Dummies Questions & Answers 6 08-02-2005 12:30 PM
really dumb question... justchillin UNIX for Dummies Questions & Answers 3 08-06-2001 01:02 AM
dumb question madhab99 UNIX for Dummies Questions & Answers 1 12-20-2000 07:41 PM