Skip to main content
14 events
when toggle format what by license comment
Feb 1, 2022 at 15:15 history edited Stephen Kitt CC BY-SA 4.0
Mention SC2181.
Feb 1, 2022 at 14:05 vote accept Manuel Jordan
Feb 1, 2022 at 14:05 comment added Manuel Jordan @StephenKitt valuable the update of your answer. Well done! - I work how the ... run a command block, but calling other functions than calling the command directly, it to reuse code and logic through methods
Feb 1, 2022 at 13:41 history edited Stephen Kitt CC BY-SA 4.0
Add some explanations.
Feb 1, 2022 at 13:31 comment added Stéphane Chazelas @ManuelJordan Saving previous exit status in a variable makes sense if you're not using it straight away like in: cmd; ret=$?; other-cmd; if [ "$ret" -eq 0 ] (or if (( ret == 0 ))...) or if you need to use it several time, like cmd; ret=$?; if (( ret == 0 )); ...; fi; return "$ret"...
Feb 1, 2022 at 13:20 comment added Stephen Kitt @ManuelJordan unfortunately many tutorials are written by people who don’t know this sort of thing.
Feb 1, 2022 at 13:14 comment added Manuel Jordan @StéphaneChazelas I saw many tutorials and some posts through StackOverflow using the if [[ $resultVerification -eq 0 ]]; then approach
Feb 1, 2022 at 13:07 comment added Stéphane Chazelas @ManuelJordan, to me those [ "$?" -eq 0 ] just betray the fact that the author doesn't know how shell constructs work.
Feb 1, 2022 at 13:06 comment added Manuel Jordan @StephenKitt pls consider to add a special note about why [[ ]] are not used
Feb 1, 2022 at 13:05 comment added Manuel Jordan @StéphaneChazelas the purpose is have a better readability - exists many if/else blocks, so have many resultVerification=$? makes verbose the code.
Feb 1, 2022 at 13:00 comment added Stéphane Chazelas Also, the verifyIfFileExists function should probably just be verifyIfFileExists() [[ -e $1 || -L $1 ]] with no need to call return explicitly.
Feb 1, 2022 at 12:55 comment added Stéphane Chazelas Actually, those [[ $? -eq 0 ]] always sound very silly to me, that's running a [[...]] command that returns true if the previous command returned true. Why not doing cmd; [[ $? -eq 0 ]]; (exit "$?"); (( $? == 0 )); (( ! $? )); if [ "$?" -eq 0 ]... while we're at running commands that carry on the exit status of the previous command.
Feb 1, 2022 at 12:55 comment added Manuel Jordan The command could return either 0 or 1 - and I need explicitly use -eq with 0 or 1
Feb 1, 2022 at 12:52 history answered Stephen Kitt CC BY-SA 4.0