Differences between revisions 9 and 10
Revision 9 as of 2009-06-09 19:47:30
Size: 2735
Editor: localhost
Comment:
Revision 10 as of 2009-06-17 23:56:45
Size: 2745
Editor: localhost
Comment: numbered list items for easy referencing (by lazy not-logging-in ferret)
Deletions are marked like this. Additions are marked like this.
Line 7: Line 7:
 * '''Floating point math'''. Bash has only [[ArithmeticExpression|integer math]]. Use `bc(1)` or [[AWK]] instead.  1. '''Floating point math'''. Bash has only [[ArithmeticExpression|integer math]]. Use `bc(1)` or [[AWK]] instead.
Line 9: Line 9:
 * '''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.  1. '''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.
Line 11: Line 11:
 * '''Associative arrays''' (fixed in bash 4.0). Use AWK or perl or Tcl instead.  1. '''Associative arrays''' (fixed in bash 4.0). Use AWK or perl or Tcl instead.
Line 13: Line 13:
 * '''Fancy ProcessManagement'''. Bash has nothing analogous to `select(2)` or `poll(2)`. Use C instead.  1. '''Fancy ProcessManagement'''. Bash has nothing analogous to `select(2)` or `poll(2)`. Use C instead.
Line 15: Line 15:
 * '''XML and HTML''' (or alike) parsing. You'd need external tools for that, at best, use Perl.  1. '''XML and HTML''' (or alike) parsing. You'd need external tools for that, at best, use Perl.
Line 17: Line 17:
 * '''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.  1. '''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.
Line 19: Line 19:
 * '''Text Processing'''. Though Bash has fairly advanced string manipulation features it's not designed for this. The shell is made to run commands, if are only processing text, an AWK or perl script is going to be much much MUCH faster. If you are going to process text with bash, be sure to learn about the pitfalls associated with `read`.  1. '''Text Processing'''. Though Bash has fairly advanced string manipulation features it's not designed for this. The shell is made to run commands, if are only processing text, an AWK or perl script is going to be much much MUCH faster. If you are going to process text with bash, be sure to learn about the pitfalls associated with `read`.
Line 21: Line 21:
 * '''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.  1. '''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.
Line 23: Line 23:
 * '''Variable declarations'''. While you can do some limited amount of declaration with the builtin declare command, There is no protection against misspelling variable names. In each case where you type a variable name wrong, you will have to run the program, discover that it fails, and waste time finding it, though using "set -u" might help.  1. '''Variable declarations'''. While you can do some limited amount of declaration with the builtin declare command, There is no protection against misspelling variable names. In each case where you type a variable name wrong, you will have to run the program, discover that it fails, and waste time finding it, though using "set -u" might help.
Line 25: Line 25:
 * '''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.  1. '''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.

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. Floating point math. Bash has only integer math. Use bc(1) or AWK instead.

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

  3. Associative arrays (fixed in bash 4.0). Use AWK or perl or Tcl instead.

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

  5. XML and HTML (or alike) parsing. You'd need external tools for that, at best, use Perl.

  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. Text Processing. Though Bash has fairly advanced string manipulation features it's not designed for this. The shell is made to run commands, if are only processing text, an AWK or perl script is going to be much much MUCH faster. If you are going to process text with bash, be sure to learn about the pitfalls associated with read.

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

  9. Variable declarations. While you can do some limited amount of declaration with the builtin declare command, There is no protection against misspelling variable names. In each case where you type a variable name wrong, you will have to run the program, discover that it fails, and waste time finding it, though using "set -u" might help.

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


CategoryShell

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