On Wed, 7 Sep 2016 15:19:23 -0700 Evan Gates <evan.ga...@gmail.com> wrote:
Hey Evan, > I'm glad you quoted! I do have a couple questions and discussion > points I'd value your feedback on. I'll do my best to answer your question. > Why all the extraneous semicolons? I see this a lot in awk, too. I > think it tends to be a reflex for C programmers. Yes it is a reflex. The semicolons don't hurt anybody and I actually am not that much of a shell-god to really exactly know where I can get rid of them. > Why not quote "$ret"? You don't have control over the environment in > which the user will run the script. I know it sounds stupid, but I > have literally seen a script run in a case where IFS=0 and if [ $? -ne > 0 ] broke. And it was a legitimate usage. I don't know about such environments. The question is if $? would ever return something that is something else than a number. > And the following purely style questions: > > What are your thoughts on > FORMAT=$(file -ib "$TMP") FORMAT=${FORMAT%;*} > instead of using the file | cut? I tend towards using shell parameter > expansion instead of piping. I think I started to do so in order to > save the fork and pipe, but now it just comes more naturally to me. I honestly have to say that I'm not comfortable with those shell-tricks and in my opinion this lowers readability very much. If this was a part of the script that was executed 1 million times I would think about using "shell-native" functions, but this is just done once and you immediately see what it does because cut(1) is a common tool. For shells, I like to go for the UNIX approach. Use the provided Posix tools to solve a task and avoid builtin stuff, especially magic syntax, as much as possible. > I still highly recommend not using all cap variables. I'm not sure > where the trend started, I don't see it in any other language (does > pop up in makefiles). I will think about making this change, but will wait for your feedback on above so I could pack this into one commit. Cheers FRIGN -- FRIGN <d...@frign.de>