Add a bash script to path
Try this:
- Save the script as
apt-proxy
(without the.sh
extension) in some directory, like~/bin
. - Add
~/bin
to yourPATH
, typingexport PATH=$PATH:~/bin
- If you need it permanently, add that last line in your
~/.bashrc
. If you're usingzsh
, then add it to~/.zshrc
instead. - Then you can just run
apt-proxy
with your arguments and it will run anywhere.
Note that if you export
the PATH variable in a specific window it won't update in other bash instances.
You want to define that directory to the path variable, not the actual binary e.g.
PATH=$MYDIR:$PATH
where MYDIR
is defined as the directory containing your binary e.g.
PATH=/Users/username/bin:$PATH
You should put this in your startup script e.g. .bashrc such that it runs each time a shell process is invoked.
Note that order is important, and the PATH is evaluated such that if a script matching your name is found in an earlier entry in the path variable, then that's the one you'll execute. So you could name your script as apt-get
and put it earlier in the path. I wouldn't do that since it's confusing. You may want to investigate shell aliases instead.
I note also that you say it works fine from your current directory. If by that you mean you have the current directory in your path (.
) then that's a potential security risk. Someone could put some trojan variant of a common utility (e.g. ls
) in a directory, then get you to cd to
that directory and run it inadvertently.