2014-02-24 199 views
0

我想在一行腳本中克隆和安裝依賴關係。 git clone https://github.com/Study-Master/Java-WebSocket.git /tmp/socket && cd /tmp/socket && mvn install -Dmaven.test.skip=true,這就是我輸入的內容。但是這個命令會離開當前目錄並在執行後轉到/tmp/socket。有什麼方法可以保持在當前目錄中。bash腳本後留在當前目錄

回答

8

有什麼辦法可以讓我留在當前目錄中。

是。在子shell執行你的命令,即說(command)(括號括內的命令):

(git clone https://github.com/Study-Master/Java-WebSocket.git /tmp/socket && cd /tmp/socket && mvn install -Dmaven.test.skip=true) 
2

只需保存你需要的目錄即可。

PWD=$(pwd) 

...執行pwd並保存輸出到$PWD

因此您的命令看起來是這樣的:

PWD=$(pwd); git clone https://github.com/Study-Master/Java-WebSocket.git /tmp/socket && cd /tmp/socket && mvn install -Dmaven.test.skip=true; cd $PWD 

而且你回來了。

+1

更重要的是,使用'pushd'和'popd'。 – dreamlax

+0

更好的是'cd -' – BroSlow

+0

Right @BroSlow - 忘了'cd -'回到'$ OLDPWD'。 – zero0