|
|
Bash shell nicest scripting features
toucheatout 2007-08-15 16:02 Linux
Linux's bash shell is certainly one of the most comfortable shells around. While reading its (4800+ lined) man page is certainly worth it, here are highlighted some features. Pattern matchingThis feature derives from the evaluation of a conditional expression, in the [[ expression ]] form. Pattern matching occurs with == and !=, though the most powerful operator is =~, as it allows backreferencing portions of the matched (extended) expression (similarly to what is commonly done with sed and perl), through the BASH_REMATCH array. String manipulationSubstring are easily obtained using the ${VAR:offset[:length]} form. To surf on the last example, Length of a variable is also directly obtained - mnemonic : same character as number of arguments in a script Arithmetic expressionsSimply obtained using $(( expression )). For instance the date in 3 days |
|