4 ms·
Won't it break when one of the commands returns non-zero? I think you can replace the & with ;
by csours 4y ago
Won't it break when one of the commands returns non-zero? I think you can replace the & with ;
- Linux-Fan 4y agoThe script has single `&` which means the respective commands will run in background (and in parallel!) which effectively ignores their return codes.
- 2OEH8eoCRo0 4y ago&& would & detaches them essentially running them in parallel?
- ukuina 4y agoDefinitely missing one & after the git clone, else the cd into the directory after will fail, assuming the git clone takes non-zero time to execute.
- philsnow 4y agoyeah that one should definitely be more like { git clone ... ; cd "$1"; ./configure; make; make install } & to run the group command (I had to look up the term in man bash) all in the background. Using group commands can be kind of weird though because they're run in the environment of the running shell, so % mkdir -p /tmp/foo && cd /tmp/foo && pwd /tmp/foo % { mkdir bar; cd bar; echo $BASH_SUBSHELL ; } 0 % pwd /tmp/foo/bar but if you do the group command in the background, bash runs it in a subshell[0] and the current directory for your shell doesn't change: % mkdir -p /tmp/foo && cd /tmp/foo && pwd /tmp/foo % { mkdir bar; cd bar; echo $BASH_SUBSHELL ; } & 1 % pwd /tmp/foo [0] From man bash: If a command is terminated by the control operator &, the shell executes the command in the background in a subshell.
- paulddraper 4y agoNo, first because it's put in background. Second because there's no `-e`.
- ketralnis 4y agoNo, & isn't the same as && which I think is what you're thinking. & is for backgrounding: #!/bin/sh date sleep 5 & # forks the command into the background, we proceed immediately date wait # pauses until the backgrounded sleep returns date has output Fri Apr 14 13:17:00 PDT 2023 Fri Apr 14 13:17:00 PDT 2023 Fri Apr 14 13:17:05 PDT 2023