Vikash B Vikash B - 24 days ago 10
Linux Question

linux source a symbolic link

I have a bash script which i want to call from any directory, but i don't want to add the directory it is in to PATH as it is filled with lots of other scripts which will just clutter.

The script in question manipulates environment variables, so i have to source it.
I tried creating an alias

alias aliastoscript="/path/to/script"
source aliastoscript #This does not work says no such file


I also can't copy the script itself to a different location as it depends on the directory structure and other scripts in the directory.

So i tried a symlink to a location already in path:

ln -s /path/to/script /directory/already/in/path/myscript


But this does not work either:

source myscript #says no such file exists


Can anyone suggest how i achieve this? And why does the symlink approach not work?

If it makes any difference, i am using a zsh shell on ubuntu 14.04

EDIT:

The answer given below works, but i also wanted to know why the symlink approach was not working.
Here is the sequence of commands

ln -s /path/to/script /directory/already/in/path/myscript
#Now there is a symlink called myscript in a directory which is in PATH

source myscript arg1 #This throws an error saying no such file myscript,
#but it is not supposed to happen because myscript resides in a directory which is in PATH


EDIT 2:
I just figured what i was doing wrong, the symlink i created, i had used relative paths, totally stupid of me, using absolute paths it worked like a charm.

Answer

Try replacing:
alias aliastoscript="/path/to/script"

with:
export aliastoscript="/path/to/script"

Comments