如何写在bash shell中一个精美雅致linux命令 [英] how to write a beautifully elegant linux command in bash shell
问题描述
我跑在我的虚拟机是在Ubuntu 12.04几个Web应用程序。
I'm running several web applications in my VM which is on Ubuntu 12.04.
我发现自己键入以下经常当我ssh到我的虚拟机。
I find myself typing the following very often when I ssh into my VM.
-
CD /var/virtual/app1.com /
-
CD /var/virtual/app2.com /
-
CD /var/virtual/app3.com /
cd /var/virtual/app1.com/
cd /var/virtual/app2.com/
cd /var/virtual/app3.com/
每个行重新presents为我执行某些指令的独立的Web应用程序根目录。
Each line represents a separate webapp root directory for me to perform certain instructions.
这是懒惰的程序员询问是否有对我来说键入方式。
This is the lazy programmer asking if there is a way for me to type.
-
go_app1
-
go_app2
-
go_app3
go_app1
go_app2
go_app3
我知道该怎么做上面使用bash脚本。
I know how to do the above using bash script.
但我最终会打字
./GoApp.sh -app app1
我要让只需键入go_app1它更优雅。
I want to make it more elegant by simply typing go_app1.
建议吗?
编辑:
我用的是收视率最高的答案,我在Ubuntu得到这个错误信息。
I used the top-rated answer and I got this error message in Ubuntu.
https://gist.github.com/simkimsia/7336019
去哪儿错了?
EDIT2:
我已经重写了错误到这里的另一个问题是命令没有找到的消息时,我尝试在.bashrc中添加命令
I have rewritten the error into another question here at command not found message when I try to add command in .bashrc.
推荐答案
定义一个别名为每肯定会工作。但是,既然你有以下的模式所需的多个快捷键,可以考虑的功能。
Defining an alias for each will certainly work. But since you have multiple desired shortcuts following a pattern, consider a function.
function go_app() { cd /var/virtual/app$1.com/; }
用法:
go_app 1
把函数定义在〜/ .bashrc。
Put the function definition in ~/.bashrc.
这篇关于如何写在bash shell中一个精美雅致linux命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!