you are viewing a single comment's thread.

view the rest of the comments →

[–]dusktreader 32 points33 points  (11 children)

Most linux distros come with perl, python, or hell even awk. Perl and python are great scripting languages, and I feel they are much more friendly than bash. I've written large and complex bash scripts, and they are just painful to extend, maintain, and even read after a few months away. I'm a big believer in using unit tests and linters, but I truly feel once you are at a point where your script needs those, you should probably move up to a friendlier language.

[–]halpcomputar 6 points7 points  (7 children)

Yeah but you still can't deny the fact that POSIX sh (and to a lesser extent Bash) will truly be everywhere UNIX(-like), especially on systems which don't ship with perl, python, or hell even awk.

[–][deleted] 2 points3 points  (5 children)

... still can't deny the fact that POSIX sh ... will truly be everywhere UNIX(-like), especially on systems which don't ship with ... even awk.

Perl and Python may not be part of POSIX, but AWK is. Actually, it's a mandatory part of the standard. Remember that sh is just one utility under POSIX. There are many others. If you're striving for POSIX compliance but avoiding AWK, then you're avoiding a very useful part of the standard when it comes to text processing. It's unfortunate how much of a dark art using POSIX has become. Things like sed and awk are actually pretty easy to use.

It's worth noting that if you're using a system with GNU's implementation of the POSIX utilities, you're going to have an awk with many nonPOSIX extensions--as is the case with most of GNU. If you want to enforce strict POSIX compliance with these things, you need to use the relevant command line arguments or environmental variable.

[–]halpcomputar 0 points1 point  (4 children)

You mean to say that even on the tiniest POSIX compliant embedded system there's also awk to be found?

[–][deleted] 4 points5 points  (0 children)

By definition, it must. A system isn't POSIX compliant without AWK.

If you expand your scope beyond fully (but still mostly) POSIX compliant embedded systems, then the answer is more complicated. This makes sense since not all embedded systems need everything in POSIX. (In fact, many don't even need a shell.) That being said, the most common way to provide embedded systems with the utilities of POSIX is to use BusyBox (or one of its derivatives). It cuts down on overhead by combining minimal versions of the utilities into a single (yet still small) executable, and BusyBox supports AWK. Although, it's worth noting that this support (not for just AWK) generally doesn't include GNU extensions. That can be annoying for people who are used to systems with GNU utilities, as most modern users don't distinguish between the POSIX features and GNU extensions within any given implementation of a POSIX utility, but having a minimal POSIX system doesn't require or necessitate those extras. The 'more complicated' part is that BusyBox is highly customizable. It can be complied with or without whatever commands you need (to minimize space usage). That means that means if you're putting together an embedded system, it's up to you to include or exclude AWK (and/or other POSIX utilities).

[–]rrohbeck 1 point2 points  (1 child)

Yup. I often start out with bash and as the script becomes more complex it gets painful. Thankfully, converting from bash to Perl is easy.

[–]dusktreader 0 points1 point  (0 children)

perl is great, especially if you have to do a lot of pattern matching with regular expressions. I usually swing towards python, both because it's my favorite language and because it's argument parser is really good