Git 如何在Shell脚本中更改目录?
这是我第一次创建Shell脚本 目前我正在使用nodejs,我正在尝试创建一个Shell脚本并在其中使用git 我的脚本是什么样子的 这个脚本位于我的桌面上,可以正常工作(是的,我已经安装了git) 我想要什么 下载git存储库后,我想:Git 如何在Shell脚本中更改目录?,git,shell,Git,Shell,这是我第一次创建Shell脚本 目前我正在使用nodejs,我正在尝试创建一个Shell脚本并在其中使用git 我的脚本是什么样子的 这个脚本位于我的桌面上,可以正常工作(是的,我已经安装了git) 我想要什么 下载git存储库后,我想: cd /site npm install 我已经安装了Nodejs和NPM 我试过的 我只想进入创建的文件夹并运行命令npm install,因此我想这样做: #!/bin/bash git clone git://github.com/Tmeister/N
cd /site
npm install
我已经安装了Nodejs和NPM
我试过的
我只想进入创建的文件夹并运行命令npm install
,因此我想这样做:
#!/bin/bash
git clone git://github.com/Tmeister/Nodejs---Boilerplate.git site
echo "cd /site"
echo "npm install"
我也读过关于这个问题的书,我试过了
#!/bin/bash
git clone git://github.com/Tmeister/Nodejs---Boilerplate.git site
alias proj="cd /site"
proj
echo "npm install"
但是什么都不管用
有谁能帮我吗?这可能比你想象的要简单(因为你一直在编写bash(或任何你使用的shell)“脚本”,只需使用命令行): 为了使其更加健壮,只有在
cd-site
成功的情况下才运行npm
(更多信息请参见):
就因为我读了一些关于的文章,这里还有另一个版本:
#!/bin/bash
OLDPWD=$(pwd)
git clone git://github.com/Tmeister/Nodejs---Boilerplate.git site \
&& cd site && npm install && cd "$OLDPWD"
function atexit() { cd "$OLDPWD"; }
trap atexit EXIT # go back to where we came from, however we exit
您可能是指没有斜杠的
cd站点
。echo
用于在屏幕上显示文本。在退出
之前刻录cd有什么意义?如果脚本没有,会有什么不同?
#!/bin/bash
git clone git://github.com/Tmeister/Nodejs---Boilerplate.git site
cd site
npm install
cd - # back to the previous directory
git clone git://github.com/Tmeister/Nodejs---Boilerplate.git site
cd site && npm install && cd -
#!/bin/bash
OLDPWD=$(pwd)
git clone git://github.com/Tmeister/Nodejs---Boilerplate.git site \
&& cd site && npm install && cd "$OLDPWD"
function atexit() { cd "$OLDPWD"; }
trap atexit EXIT # go back to where we came from, however we exit