问题描述
我开发在Windows计算机上。我需要为Linux命令行的唯一地方是混帐击。现在的问题是:当我打开它,我在主目录。我不得不将目录更改为我的工作区,如:
I am developing on a windows machine. The only place I need for linux command line is Git Bash. The problem is: When I open it, I am in the home directory. I have to change the directory to my workspace, like:
cd ../../../d/work_space_for_my_company/project/code_source
我可以在一个sh文件把这个包,所以我不必手型它了吗?这应该是简单,但我对Linux命令行零知识。我真的AP preciated如果你走在我
通过如何创建sh文件。
Can I wrap this in a .sh file so I don't have to hand-type it anymore? This should be simple but I have zero knowledge about Linux command line. I am really appreciated If you can walk methrough how to create that .sh file.
推荐答案
只写一行到文件cd.sh,然后做这在shell提示符下:
Just write that line to a file "cd.sh", then do this from your shell prompt:
. ./cd.sh
或者你也可以创建一个别名或函数的 $ HOME / .bashrc中
文件:
foo() { cd /d/work_space_for_my_company/project/code_source ; }
如果目录名称中包含空格或其他shell元字符,你需要引号;它不会伤害它们添加即使他们没有必要的:
If the directory name includes spaces or other shell metacharacters, you'll need quotation marks; it won't hurt to add them even if they're not necessary:
foo() { cd "/d/Work Space/project/code_source" ; }
(请注意,我省略了../../ ..你不需要它。)
(Note that I've omitted the "../../.."; you don't need it.)
编辑:如果添加了行
foo
函数定义后,你的.bashrc,你的shell将在该目录中启动。
to your .bashrc after the function definition, your shell will start in that directory.
这篇关于GIT巴什 - 如何默认为其他目录,而不是主目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!