Hacker News new | past | comments | ask | show | jobs | submit login

The bash-example is not very bashy. It is sh, like the header says. Bash fully supports a native for:

  for i in {0..5};do
      echo "$1"
  done



Interestingly, this comment states that Bash is not available in all POSIX. Here is where I get lost. http://blog.fourthbit.com/2014/03/01/the-best-programming-la...


Yes, that is correct. Bash has additional functionality (and the for-loop I showed could very well be a part of that). If you want posix, better stick to dash, the code he showed.

But bash with its additional features (like associative arrays) is much more comfortable, so if you know you can use bash - because the target is GNU/Linux - it is a good idea to use them.


Sh has for; it does not have the {a..b} construct. But you can write it as:

    for i in `seq 0 5`; do
        echo "$i"
    done
and that will work perfectly well on dash.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: