Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
483 views
in Technique[技术] by (71.8m points)

linux - Add a bash script to path

I want to add a small script to the linux PATH so I don't have to actually run it where it's physically placed on disk.

The script is quite simple is about giving apt-get access through a proxy I made it like this:

#!/bin/bash
array=( $@ )
len=${#array[@]}
_args=${array[@]:1:$len}
sudo http_proxy="http://user:password@server:port" apt-get $_args

Then I saved this as apt-proxy.sh, set it to +x (chmod) and everything is working fine when I am in the directory where this file is placed.

My question is : how to add this apt-proxy to PATH so I can actually call it as if it where the real apt-get ? [from anywhere]

Looking for command line only solutions, if you know how to do by GUI its nice, but not what I am looking for.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this:

  • Save the script as apt-proxy (without the .sh extension) in some directory, like ~/bin.
  • Add ~/bin to your PATH, typing export PATH=$PATH:~/bin
  • If you need it permanently, add that last line in your ~/.bashrc. If you're using zsh, 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...