bashcookbook
-
bash has 4 prompt strings; PS2 is used when you haven't completed your input in response to the initial prompt (PS1), on the command line.
about 12 hours ago
from Identica
-
With a select, the actual input is in the variable "REPLY" but the matching value is in the variable you supplied on the select command.
10:14 AM Nov 11th
from Identica
-
"select VAR in x y z ; do ..." displays your choices: "1) x 2) y 3) z" and prompts (PS3) for input. If you type 2 then VAR is set to "y"
10:45 AM Nov 9th
from Identica
-
Running a "select" in your script prints the prompt "#?", the value of PS3, one of 4 prompt variables in bash. The usual prompt is in PS1.
10:51 AM Nov 4th
from Identica
-
Make simple text-based menus in your script w/ select. Ex: select VAR ; do ls -ld "$VAR" ; done Save it as "ils" Run it: bash ils *
1:21 PM Nov 2nd
from Identica
-
Also new in bash 4.0: a case can end with ";;&" not just ";;" or ";&" - it continues testing other case patterns for more matches.
9:37 AM Oct 29th
from Identica
-
New in bash 4.0, a case can end with ";&" instead of ";;" and it executes the statements of the next case, too (regardless of its pattern).
9:39 AM Oct 28th
from Identica
-
You can have a space in your case pattern but you need to escape it, e.g.: *\ *) echo spacey ;;
so that bash knows it's all one pattern.
10:12 AM Oct 27th
from Identica
-
There is no "default" case, but using *) as the last case will accomplish just that - since "*" matches anything. Be sure it's the last one!
9:30 AM Oct 26th
from Identica
-
Your "case" patterns can be in parens ( *.c ) or just end with right paren: *.c ) The left paren is allowed but optional.
11:07 AM Oct 23rd
from Identica
-
Want multiple patterns in one case? Use an or-bar "|" between each pattern. Example: *.[ch] | *.java ) echo source;;
10:31 AM Oct 22nd
from Identica
-
Each case in a case statement is bash pattern matching, not regular expressions, then a ')' then statements then ';;'
10:55 AM Oct 21st
from Identica
-
bash case example: case "$FILENM" in *.jpg) echo image ;; *.[ch]) echo C-lang ;; *) echo unknown;; esac (ugly as 1 line; tweet fm'ts R ltd.)
10:50 AM Oct 19th
from Identica
-
Whereas C and perl have a "switch" statement with each value or pattern preceded by a "case" keyword, bash calls it a "case" statement.
10:23 AM Oct 15th
from Identica
-
An advantage to using [[ ]] for an if statement: you have the =~ operator which matches regular expressions. (avail. in bash 3.0 and newer)
8:24 PM Oct 9th
from Identica
-
commands inside "( )" run in a subshell; ( cd /tmp; X=7; other_stuff; ) after that, U R back to prev. directory, prev. value of X.
10:58 AM Oct 7th
from Identica
-
1 other use of ":", since it returns 0, use it like "true" as "while : loop ; do ... done" where "loop", an arg to ":", is just a comment.
10:53 AM Oct 6th
from Identica
-
: <<'END' with lots of text after it, as comments, w/o needing a leading "#". The ":" does nothing, but << swallows the text up to END.
10:36 AM Oct 5th
from Identica
-
We just reached 800 followers! Hurray!! Since it's Follow Friday suggest @ to others and let's aim for 1,000.
11:10 AM Oct 2nd
from web
-
":" is a "no-op" (does nothing) but bash expands any arguments and does any i/o redirections; a useful (?) example next time! (hint: p.83)
10:36 AM Oct 2nd
from Identica
|
|