简体   繁体   English

如何在cd和运行脚本或在非主目录中运行脚本的别名

[英]How can I make an alias both cd and run a script or run a script in a non-home directory

How can I make an alias either run a script in another directory or both cd and run the script? 如何创建别名要么在另一个目录中运行脚本,要么同时运行cd并运行脚本?

I have commands in my .bashrc file to cd /home/myname/my_dir 我的.bashrc文件中的命令为cd /home/myname/my_dir

and also 并且

rake sunspot:solr:start  

when I am in our app directory (that contains the /script subdirectory). 当我在我们的app目录(包含/ script子目录)时。

I have not been able to put either put the directory in the rake command or have the alias do a cd and then the rake command that it currently does. 我无法将目录放在rake命令中,或者让别名执行cd,然后执行当前执行的rake命令。

For instance I attempted rake /home/my_dir/out_code_directory/sunspot:solr:start RAILS_ENV=test but that didn't work. 例如,我尝试了rake /home/my_dir/out_code_directory/sunspot:solr:start RAILS_ENV=test但是没有用。

alias rakesolr='cd dir; rake sunspot:solr:start; cd -'

works for me (in bash). 适合我(在bash)。 Does that do what you need? 这样做你需要的吗?

[ Ahh, semicolon ! [啊, 分号! Michael.] 迈克尔。]

Maybe can you edit your rake task ? 也许你可以编辑你的佣金任务吗? Or you can make a new task that do a Dir.chdir and then execute the task wanted. 或者,您可以创建一个执行Dir.chdir的新任务,然后执行所需的任务。

Edit : resource about execute a task within another here 编辑:资源约内的其他执行任务这里

为什么不编写一个小的bash脚本,cds然后执行脚本并通过别名命令运行?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM