Live data from Hacker News

Common shell script mistakes (2008)

pixelbeat.org

11–20 of 82 posts

Re: Common shell script mistakes (2008)

#11
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 abstractions, and have significant data manipulation in the shell process itself. While flexible, shell is not designed as a general purpose language and becomes unwieldly when ... "

Another person has actually solved the most important show stopper already: http://ctypes.sh.

What now remains to be solved, are a few minor, additional details, and then simply writing a good manual of how to very successfully use bash as a general-purpose language.

My personal belief is that everything that you can do in other scripting languages, you can also do in Bash, only better.

Re: Common shell script mistakes (2008)

#13

Is there a modern "JavaScript: The Good Parts" for bash? There are so many ways to do things and it's often hard to tell which is preferable.

Not sure if this is what you're looking for, but it's where I tend to go when writing something.

http://mywiki.wooledge.org/BashGuide

Re: Common shell script mistakes (2008)

#14

Is there a modern "JavaScript: The Good Parts" for bash? There are so many ways to do things and it's often hard to tell which is preferable.

Not sure if this is what you're looking for, but it's where I tend to go when writing something. http://mywiki.wooledge.org/BashGuide

I'm a big fan of this guide. I wish every language had such a clear best practices list. See also http://mywiki.wooledge.org/BashPitfalls

Re: Common shell script mistakes (2008)

#15
post #11

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…

You're missing out on Zsh ;)

Re: Common shell script mistakes (2008)

#16

Is there a modern "JavaScript: The Good Parts" for bash? There are so many ways to do things and it's often hard to tell which is preferable.

Not exactly "The Good Parts" for bash, but one might want to look at Turtle library:

https://github.com/Gabriel439/Haskell-Turtle-Library

Related: http://www.haskellforall.com/2015/01/use-haskell-for-shell-s...

Re: Common shell script mistakes (2008)

#17
post #11

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…

> My personal belief is that everything that you can do in other scripting languages, you can also do in Bash, only better.

Matrix multiplication?

Re: Common shell script mistakes (2008)

#18
Great 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?

Re: Common shell script mistakes (2008)

#19
post #11

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.

Re: Common shell script mistakes (2008)

#20
post #18

Great 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.

Post reply on HN