如何将bash脚本作为命令运行? [英] How do you run bash script as a command?

查看:67
本文介绍了如何将bash脚本作为命令运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个bash脚本,用于在无线访问媒体服务器中的文本文件中配置不同的参数.

I have a bash script, which I use for configuration of different parameters in text files in my wireless access media server.

该脚本位于一个目录中,并且由于我使用腻子进行了所有配置,因此必须使用文件的完整路径或移至包含该文件的目录.我想避免这种情况.

The script is located in one directory, and because I do all of configurations using putty, I have to either use the full path of the file or move to the directory that contains the file. I would like to avoid this.

是否可以将bash脚本保存或编辑bash脚本,以便我可以将其作为命令运行,例如,作为 cp ls 命令?>

Is it possible to save the bash script in or edit the bash script so that I can run it as command, for example as cp or ls commands?

推荐答案

脚本必须是可执行的,并且具有:

The script needs to be executable, with:

chmod +x scriptname

(或类似).

此外,您希望脚本位于PATH中的目录中.要查看您的PATH,请使用:

Also, you want the script to be located in a directory that is in your PATH. To see your PATH use:

echo $PATH

您的选择是:将文件移动(或链接)到这些目录之一,或者将其所在的目录添加到您的路径中.

Your choices are: to move (or link) the file into one of those directories, or to add the directory it is in to your PATH.

您可以使用以下方式将目录添加到PATH中:

You can add a directory to your PATH with:

PATH=$PATH:/name/of/my/directory

,如果您在文件 $ HOME/.bashrc 中执行此操作,它将自动在您的每个shell中发生.

and if you do this in the file $HOME/.bashrc it will happen for each of your shell's automatically.

这篇关于如何将bash脚本作为命令运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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