Bash is the love of my life! I have been working for years on this problem now (not full-time of course), gradually moving in the direction of finally being able to challenge this: "Inappropriate use shell is the main domain specific language designed to manipulate the UNIX abstractions for data and logic, i.e. files and processes. ... Correspondingly, please be wary of writing scripts that deviate from these abstrac…
Ok, I'll bite. >> My personal belief is that everything that you can do in other scripting languages, you can also do in Bash, only better. 1) Native JSON, XML 2) Classes, namespacing, objects 3) Multiprocessing, multithreading 4) Performance 5) Package management 6) Portability 7) Documentation 8) Runtime debugging (!set -x) I'm too tired to continue.
Common shell script mistakes (2008)
21–30 of 82 posts
Re: Common shell script mistakes (2008)
#22Will this work if you've activated set -u, fail on unset variables? Will the !-z variant do?
Re: Common shell script mistakes (2008)
#23Re: Common shell script mistakes (2008)
#24Great post. I disagree on using the concise form of the if statement, however. if [ "$var" = "find" ]; then echo "found" fi Is far more readable than its equivalent [ "$var" = "find" ] && echo "found" I understand the upside of readability. What does concision get me?
concision gets me less code to read. that's how i define "readability". but if forum commments are any indication, i know my preferences do not follow the norm. most programmers seems to prefer verbosity. however in my case verbosity slows me down.
Re: Common shell script mistakes (2008)
#25Earlier quoted context omitted.
Shell hasn't changed much, if at all, since, has it?
nope. reminds me of comments where someone is purporting to be able to assess the quality of software based only on looking to see when the last changes to the source code were made.
Re: Common shell script mistakes (2008)
#26Bash is the love of my life! I have been working for years on this problem now (not full-time of course), gradually moving in the direction of finally being able to challenge this: "Inappropriate use shell is the main domain specific language designed to manipulate the UNIX abstractions for data and logic, i.e. files and processes. ... Correspondingly, please be wary of writing scripts that deviate from these abstrac…
Ok, I'll bite. >> My personal belief is that everything that you can do in other scripting languages, you can also do in Bash, only better. 1) Native JSON, XML 2) Classes, namespacing, objects 3) Multiprocessing, multithreading 4) Performance 5) Package management 6) Portability 7) Documentation 8) Runtime debugging (!set -x) I'm too tired to continue.
IMO shell makes it very easy to work with multiple process (&). It's built in and natural.
>4) Performance
If you are carefull and know what you're doing, you can achive very good performance with the shell. Usually, better performance is achived processing less data, ie being inteligent. Rarely depends on the language (unless you care about cycle level performance, then yes :).
>6) Portability
I claim that it's way easier to depend on sh being on a (UNIX) system than $SCRIPTING_LANG.
>7) Documentation
?? You can mess up documentation in any language.
Re: Common shell script mistakes (2008)
#27Great post. I disagree on using the concise form of the if statement, however. if [ "$var" = "find" ]; then echo "found" fi Is far more readable than its equivalent [ "$var" = "find" ] && echo "found" I understand the upside of readability. What does concision get me?
concision gets me less code to read. that's how i define "readability". but if forum commments are any indication, i know my preferences do not follow the norm. most programmers seems to prefer verbosity. however in my case verbosity slows me down.
Re: Common shell script mistakes (2008)
#28> Just test the string directly like [ "$var" ] && echo "var not empty" Will this work if you've activated set -u , fail on unset variables? Will the !-z variant do?
Re: Common shell script mistakes (2008)
#29Great post. I disagree on using the concise form of the if statement, however. if [ "$var" = "find" ]; then echo "found" fi Is far more readable than its equivalent [ "$var" = "find" ] && echo "found" I understand the upside of readability. What does concision get me?
concision gets me less code to read. that's how i define "readability". but if forum commments are any indication, i know my preferences do not follow the norm. most programmers seems to prefer verbosity. however in my case verbosity slows me down.
Re: Common shell script mistakes (2008)
#30Python is a good alternative as well.