I'm very simply wondering if, in a bash script,
a new line is functionally 100% equivalent to &&?
e.g.:
#!/bin/bash
7z x "${file}"
mv "${file}" "${new_file}"
vs
#!/bin/bash
7z x "${file}" && mv "${file}" "${new_file}"
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
$fileis a parameter that should be7z x -- "$file"andmv -- "$file" "$new_file"(NB some people seem to think that${var}is equivalent to"$var") – Chris Davies Mar 09 '24 at 19:35set -eat the beginning of the second example? Would it then behave the same as the first snippet? – Meto Mar 09 '24 at 21:42$Aas"$A"prevents shell expandingAinto multiple words. Writing$A_Bas${A}_Bprevents shell trying to expand an unknown variableA_Binstead of expandingAand appending_B. Many of the extended expansions (array, substring, trimming) require the{..}to control the internal syntax. – Paul_Pedant Mar 10 '24 at 10:117z … && mv …will only runmvif7zsucceeds, but will continue running aftermvif7zfails; whereasset -e; 7z …; mv …will exit if any command fails, includingmv, and anything followingmvwon’t run if7zormvfails. – Stephen Kitt Mar 10 '24 at 12:46