Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script path 1

Status
Not open for further replies.

codemut

Programmer
Feb 29, 2008
26
US
How should a script in another directory be run, such as /another/directory/script ? My shell is bash.
 
Exactly like you said, just /another/directory/script.

If you want to be able to run it from anywhere by just typing script, add that directory to your PATH:

Code:
PATH=$PATH:/another/directory

You can add this to your .profile or .bash_profile to set it automatically every time you log in.

Annihilannic.
 
Thanks Annihilannic,

With: /another/directory/script, returned is: bash: /another/directory/script: No such file or directory

With: ./another/directory/script, the terminal hangs.

While the following seems to work:
cmd="cd another/directory; ./script; cd .."
eval $cmd
unset cmd
... it seems overkill.
 
I agree that's overkill. What is the the first line of the script? Does it contain a shebang line (e.g. #!/path/to/bash)? If so, is it pointing to the correct location of your bash shell?

What directory are you in when you run the command? Is another/directory a subdirectory of your current directory, or is it located in /?

Annihilannic.
 
The first line is #!/usr/bin/gawk -f, which works fine executing within the current directory. Hope to execute files that are in either a subdirectory or outside the current directory (which may require the full path from / ).
 
I think it must be something related to the contents of the script itself, without seeing them it's difficult to say what's going wrong here.

Annihilannic.
 
Hi zedlan,

It looks like there is a bit of confusion with absolute addressing and relative addressing.

/another/directory/script
is absolute addressing (where script is in directory which is in another - a directory on /)

./another/directory/script is the same as
another/directory/script which is the same as
$PWD/another/directory/script
is relative addressing, ie relative to the current directory (and can be several directories 'below' /)

To find the script script in a sub-directory somewhere 'below' the current working directory and give it its full path, you can use:
my_script=`find $PWD -name "script" -print`


I hope that helps.

Mike
 
Seems like the "script" reads something in another/directory ...
What about this ?
Code:
(cd another/directory; ./script)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
What comes after the "#!/usr/bin/gawk -f ". Is the filename specified given in absolute path?
 
PHV, your suggestion is closest to my ideal. Given that parentheses around a command starts a subshell, maybe one ought to include ";exit" near the end.

Edcrosbys, after the first line in the script it is just a typical gawk script with: BEGIN { ...

Mike042 and Annihilannic, you raise valid points.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top