Dumb question on script execution

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Dumb question on script execution
# 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!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

really dumb MV command question

Hi, Im trying to do move a file like this as mart of my script on Solaris mv /path/to/file/file.txt .. mv: cannot rename /path/to/file/file.txt to ../file.txt: Permission denied. Im just trying to move it up one level using the following command on a bunch of directories: find... (4 Replies)
Discussion started by: ideal2545
4 Replies

2. Shell Programming and Scripting

Help with dumb for-loop question

can anyone please suggest what is wrong with this command: for i in ; do cat ~/Downloads/Project/p0s0n15.tcl>>~/Downloads/Project/p0s0n15_$i.tcl; ./setdest -n 15 -p 0 -M 5 -t 100 -x 500 -y 500 >>~/Downloads/Project/p0s0n15_$i.tcl; cat... (3 Replies)
Discussion started by: amithkhandakar
3 Replies

3. UNIX for Dummies Questions & Answers

Dumb find question

All, For some reason I can't figure out why I can't wildcard my find statement to check for anything with a wildcard after. I can before the -name but not after. ie. find . -name *test works but find . -name test* gives me the error: find: paths must precede expression Usage: find ... (1 Reply)
Discussion started by: markdjones82
1 Replies

4. UNIX for Dummies Questions & Answers

this is a very dumb question...i know... :(

hi, when we do an "ls -l" on a directory, we get the listing of the contents of that dir... what is the meaning of some numbers...example in ; -rw-r--r-- 1 idr supp 0 Feb 18 19:41 dmesg drwxrwsrwx 2 root sys 96 Dec 27 15:31 test09 drwxr-xr-x 3 bin ... (1 Reply)
Discussion started by: cromohawk
1 Replies

5. UNIX for Dummies Questions & Answers

Another dumb question but...

When getting a listing of files using "ls -l", my output shows the permissions, #oflinks???, owner, group, size, month-day-time, and file. In the example below, how would I know what year the file was last modified? -rw-rw-r--, 28, root, root, 2048, Oct 28 15:10, somefile.txt (2 Replies)
Discussion started by: KGee
2 Replies

6. UNIX for Dummies Questions & Answers

Another dumb question...

Probably a really easy one for you guru's out there...:rolleyes: I need to make sure the reverse address lookup daemon in rarpd, is running. How do I do so? :confused: Did a grep for the process but couldnt find it, also looked in all the normal places, /bin etc... Cheers (1 Reply)
Discussion started by: JayC89
1 Replies

7. UNIX for Dummies Questions & Answers

Ok really dumb question but...

Does anyone have detailed info on how to download the files. I go to www.freebsd.com and then i dont know what to do. I dont know why i dont know but im drawing a complete blank so is there anyone that can provide a step by step procedure for downloading/installing Linux? :confused: :confused: (3 Replies)
Discussion started by: Corrail
3 Replies

8. UNIX for Dummies Questions & Answers

script dumb question

Hi, i'm dealing with a script and I have one question. If I have these: #!/bin/bash wget http://somesite/file.tar tar xvf file.tar exit I need the line that contains the command tar to wait until file.tar is completly downloaded, but it doesn't and continues with the next line... (6 Replies)
Discussion started by: piltrafa
6 Replies

9. UNIX for Dummies Questions & Answers

really dumb question...

ok i decided to go with Mandrake so i went to the site to download it and that took me to a mirror site. ok. so once i get there were can i find the install file(s) that i need? i only see a series of folder and files. the ones that say intall are instructions but i don't see the files themselves.... (3 Replies)
Discussion started by: justchillin
3 Replies

10. UNIX for Dummies Questions & Answers

dumb question

My problem is as follows: I have to write a korn shell script which will run mutiple java applications one after one. For example, I will execute the java application A first, after it is done I will run application B. My question is how do I do this? How does my korn shell script know that... (1 Reply)
Discussion started by: madhab99
1 Replies
Login or Register to Ask a Question