添加一个bash脚本路径 [英] Add a bash script to path

查看:391
本文介绍了添加一个bash脚本路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要一个小脚本添加到Linux版的路径,所以我没有真正运行它,它的身体放置在磁盘上。

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

然后我保存这个作为apt-proxy.sh,将其设置为+ X(CHMOD),当我在这个文件所在目录一切工作正常。

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.

我的问题是:如何添加此的apt-代理 PATH 这样我就可以实际调用它,好像它在那里真正的apt-get的? [从任何地方]

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]

寻找命令行唯一的解决办法,如果你知道如何通过GUI的不错,但做的不是我期待的

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

推荐答案

试试这个:


  • 将脚本保存为的apt-代理(不包括 .SH 扩展)在某些目录中,如〜/斌

  • 添加〜/斌你的 PATH 键入出口PATH = $ PATH: 〜/斌

  • 如果你需要它永久添加最后一行在〜/ .bashrc中文件(如果你使用庆典)。

  • 然后,你可以运行的apt-代理与你的论点,它会在任何地方运行。

  • 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 file (If you're using bash).
  • Then you can just run apt-proxy with your arguments and it will run anywhere.

请注意,如果您导出它不会在其他的bash实例更新特定窗口PATH变量。

Note that if you export the PATH variable in a specific window it won't update in other bash instances.

这篇关于添加一个bash脚本路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆