Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am running a quite complicated script which changes directories and runs many other commands. All these commands are run using 'scriptname', which works fine when I execute the main script from my terminal. However, sometimes I have to ssh into a server and run the main script from there, it fails as there isn't a ./ before each command.

I'd rather not go through all the scripts and executables and add a ./ to the commands, so is there another way to solve this problem?

share|improve this question
2  
Just make sure "current directory" is in your path: superuser.com/questions/350844/… –  Digital Chris Jun 13 at 12:12
9  
I am not sure I completely agree with with adding the current directory, especially if that happens in the form of $PATH:., because it poses a security risk ... more so when you are root. But having a dedicated script path and adding that should be fine if the permissions for that path are tight. –  0xC0000022L Jun 13 at 12:15
1  
@DigitalChris, don't ever do that, it opens you to a nasty security problem (just add an executable called, e.g. sl to /tmp or somewhere else writable by you, and wait until an unsuspecting victim fat-fingers ls(1) as sl...) –  vonbrand Jun 13 at 20:50
    
@vonbrand: sl, you say? github.com/mtoyoda/sl –  Rocket Hazmat Jun 13 at 21:41
    
@RocketHazmat replace by whatever typo of a common command you like –  vonbrand Jun 14 at 10:45

3 Answers 3

up vote 12 down vote accepted

There are ways to change this behavior including adding ./ to your PATH environment variable, but this introduces a serious security risk to your environment. The way your scripts are written is really wrong and the correct solution is to go through all of them and fix the way local scripts are called. This is the only proper fix that will not introduce extra problems down the road and create security issues for you. I know it's not what you wanted to hear, but bite the bullet and do it right.

share|improve this answer
    
Thanks for the help. Since I'm using university machines, I guess it's better to be safe than sorry, so I'll amend the scripts (and curse the person who wrote them!) –  user72404 Jun 13 at 12:45
4  
@user72404: that's how developers do. Curse them predecessors. Curse them! ;) –  0xC0000022L Jun 13 at 13:01

if your scripts happen to be under /opt/housekeeping/bin, i suggest you add

export PATH=$PATH:/opt/housekeeping/bin  

to your .bash_profile or .profile or whatever your login script you use & ensure 755 permission is set as well on those scripts.

share|improve this answer
    
Why not ~/.local/bin, or even ~/bin –  Wilf Jun 13 at 13:19
1  
i do not understand Wilf, can you enlighten me –  akash Jun 13 at 13:25

you can create an alias for your script:

alias scriptfile="./scriptfile"
share|improve this answer
2  
I think the issue is he's calling a bunch of commands/scripts from within that depend on his $PATH being a certain way, so this won't help with those. –  slm Jun 13 at 21:01
    
i think you thinking that is no reason to downvote. –  user72461 Jun 13 at 21:25
    
or upvote yourself thinking that <.< –  user72461 Jun 13 at 21:28
    
I was not the one to DV this, if I did I would've left a comment as to why. –  slm Jun 13 at 22:21
    
@user72461 you can't upvote your own comments... –  strugee Jun 14 at 1:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.