madhuneal / ppss

Automatically exported from code.google.com/p/ppss
0 stars 0 forks source link

Consider using newer bash features such as '[[ ]]' and '$( )'. #39

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Currently the code uses legacy syntax such as:

  DIRECTORY=`dirname "$SRC_DIR"`
  if [ ! "$DIRECTORY" = "/" ] && [ ! "$DIRECTORY" = "." ]
  if [ ! "$ERROR" = "0" ] 
  if [ "$yn" == "y" ] || [ "$yn" == "yes" ]

In all but very old versions of Bash, one could use:

  DIRECTORY=$(dirname $SRC_DIR)
  if [[ $DIRECTORY != [/.]* ]]
  if (( ERROR != 0 ))
  if [[ $yn == y* ]]

Links which discuss some of these newer features include:

  http://mywiki.wooledge.org/BashGuide/Practices
  http://mywiki.wooledge.org/BashFAQ/031
  http://mywiki.wooledge.org/BashFAQ/082
  http://mywiki.wooledge.org/ArithmeticExpression
  http://mywiki.wooledge.org/ProcessSubstitution
  http://mywiki.wooledge.org/BashFAQ/005
  http://wiki.bash-hackers.org/syntax/ccmd/c_for

It's probably very safe to rely on version 2.0 features.
There may still be a few people without Bash 3.0 around,
but I doubt if many of them are the kinds of people who
would use ppss in the first place.  Using constructs like
[[ x =~ y ]] can really simplify the code, so maybe it
would be appropriate to change.  For safety, one could
check the Bash version at the top of the script, and bail
out if the version is too old.  If one could be confident
that users of ppss will have bash 4.0, some of the 4.0
features such as coproc may be extremely useful to ppss.
See http://wiki.bash-hackers.org/bash4 for a discussion
of coproc and other potentially useful 4.0 features such
as globstar, mapfile, checkjobs, and associative arrays.

--William L. Dye ("willdye")
Software Enginerd
Lincoln, Nebraska (USA)

Original issue reported on code.google.com by willdye on 7 Jan 2011 at 5:46

GoogleCodeExporter commented 9 years ago
Thank you for your suggestion. It would improve the readability of the code. 

Original comment by Louwrentius on 24 Jan 2011 at 7:44

GoogleCodeExporter commented 9 years ago
As for now I replaced back ticks and used != and double brackets where possible 
(search/replace with some regex).

Original comment by Louwrentius on 28 Dec 2011 at 9:40