Differences between revisions 11 and 12
Revision 11 as of 2010-08-04 19:41:53
Size: 2417
Editor: GreyCat
Comment:
Revision 12 as of 2010-08-04 21:04:45
Size: 2770
Editor: GreyCat
Comment:
Deletions are marked like this. Additions are marked like this.
Line 25: Line 25:
 1. '''Try/catch'''. Some programming languages let you wrap a command in a `try ... catch` block. This will interpret the command in a sort of "sandbox", where errors that would normally cause an abort are "caught", and trigger some sort of error-handling code. Bash does not have anything analogous to this. Any bash code you run is real code.

This is a stub. Please fill in the missing pieces.

There are certain things BASH is not very good at. There are certain tasks you shouldn't do in bash, unless you really, truly have to. It's often better to switch to a different language for most of these tasks.

  1. Speed. Do we really have to say it? Bash is slow. If speed is an important consideration, then Bash may not be the best choice.

  2. Floating point math. Bash has only integer math. Use bc(1) or AWK instead.

  3. Data structures. Bash does not have Pascal-style records (C-style structs); nor does it have pointers. Any attempt to create advanced data structures (stacks, queues, linked lists, binary trees...) will have to be done with extremely primitive hacks.

  4. Fancy ProcessManagement. Bash has nothing analogous to select(2) or poll(2). Use C instead.

  5. XML and HTML (or alike) parsing. You need external tools or libraries to do this correctly. Use xslt, tidy, xmlstarlet, perl, or some other suitable tool.

  6. Binary data. Bash has no way to store the null byte, so binary data either has to be encoded or placed awkwardly in an array. Parsing binary data is also a problem. Try perl or C.

  7. Database queries. When retrieving a tuple from a relational database, there is no way for Bash to understand where one element of the tuple ends and the next begins. In general, Bash is not suited to any sort of data retrieval that extracts multiple data values in a single operation, unless there is a clearly defined delimiter between fields. For database queries (SQL or otherwise), switch to a language that supports the database's query API.

  8. Variable typing. Like most scripting languages, Bash does not really support strong variable types. Variables are loosely categorized as scalar or array, with partial support for an integer type. But really, everything is a string.

  9. Dropping permissions. It can be tough to make a bash script safe to execute as root. In languages like C, perl, and python, you can easily drop privileges at a certain point. With bash, this is tricky, because while you can run su or sudo, you lose variables, and even the executing environment. Use a proper programming language if you have security worries.

  10. Try/catch. Some programming languages let you wrap a command in a try ... catch block. This will interpret the command in a sort of "sandbox", where errors that would normally cause an abort are "caught", and trigger some sort of error-handling code. Bash does not have anything analogous to this. Any bash code you run is real code.


CategoryShell

BashWeaknesses (last edited 2022-09-01 18:14:07 by 188)