Execute combine multiple linux commands in one lin

2019-01-12 13:26发布

I am trying to merge multiple linux commands in one line to perform deployment operation. For example

cd /my_folder
rm *.jar
svn co path to repo
mvn compile package install

9条回答
倾城 Initia
2楼-- · 2019-01-12 14:04

You can use as the following code;

cd /my_folder && \
rm *.jar && \
svn co path to repo && \
mvn compile package install

It works...

查看更多
神经病院院长
3楼-- · 2019-01-12 14:07

To run them all at once, you can use the pipe line key "|" like so:

$ cd /my_folder | rm *.jar | svn co path to repo | mvn compile package install
查看更多
一纸荒年 Trace。
4楼-- · 2019-01-12 14:09

I've found that using ; to separate commands only works in the foreground. eg :

cmd1; cmd2; cmd3 & - will only execute cmd3 in the background, whereas cmd1 && cmd2 && cmd3 & - will execute the entire chain in the background IF there are no errors.

To cater for unconditional execution, using parenthesis solves this :

(cmd1; cmd2; cmd3) & - will execute the chain of commands in the background, even if any step fails.

查看更多
登录 后发表回答