POSIX general defines three special files:
- /dev/tty
- /dev/console
- /dev/null
In addition, /
and /tmp
are also defined by POSIX.
/dev/zero
, /dev/urandom
or /dev/random
are defined in some UNIX-like operating systems. Some operating systems may not define them, or implement with different names.
Note
Here are the grammar rules, if it helps. I'm not great at reading it, but it sure looks allowed - for every pattern + list case there's also a pattern + break case. That third one would seem to indicate you might even go totally patternless. The link is here.
case_clause : Case WORD linebreak in linebreak case_list Esac
| Case WORD linebreak in linebreak case_list_ns Esac
| Case WORD linebreak in linebreak Esac
;
case_list_ns : case_list case_item_ns
| case_item_ns
;
case_list : case_list case_item
| case_item
;
case_item_ns : pattern ')' linebreak
| pattern ')' compound_list linebreak
| '(' pattern ')' linebreak
| '(' pattern ')' compound_list linebreak
;
case_item : pattern ')' linebreak DSEMI linebreak
| pattern ')' compound_list DSEMI linebreak
| '(' pattern ')' linebreak DSEMI linebreak
| '(' pattern ')' compound_list DSEMI linebreak
Anyway - it makes sense to me that it should work. The following works:
x=
if $x; then $x; else echo this doesnt happen; fi
...because the commands are not empty when parsed and the shell has something to do. I always associate a pattern with an attached list directly. And in fact, they are pretty well conjoined.
x=0
for z in a b c d e f g
do case $z in [abcd]) ;; $((x+=1))) ;; esac
done; echo "$x"
3
The spec is pretty clear about about the order of expansions and pattern - list associations. I always just naturally conjoin the two and consider them as more or less a single command. And so because the shell does something, it can check that box off. It probably has something to do with the way a C switch case works.
Best Answer
"${blah}"
and"$blah"
are portable shell syntax: they work on all POSIX-compliant shells as well as in traditional Bourne shells. POSIX also requires other features of variable expansion:${VAR#PREFIX}
,${VAR##PREFIX}
,${VAR%SUFFIX}
and${VAR%%SUFFIX}
.${VAR-DEFAULT}
,${VAR=DEFAULT}
,${VAR+FALLBACK}
and${VAR?MESSAGE}
as well as the unset-or-empty variants with:-
,:=
,:+
and:?
.${#VAR}
.In all cases, remember that the result of
$…
undergoes whitespace-splitting (more precisely, splitting at$IFS
characters) and wildcard expansion (globbing) unless it's in double quotes (or a few other contexts that don't allow multiple words).You can look up what exists in POSIX by reading the specification. Modern versions of POSIX are identical to the Open Group Base Specifications (without optional components). Older versions are a subset of Single Unix v2.
Unix-like systems without a POSIX shell are extremely rare nowadays.
/bin/sh
is a non-POSIX Bourne shell on a few systems, notably Solaris, but a POSIX shell is available (/usr/xpg4/bin/sh
on Solaris, and you should have/usr/xpg4/bin
ahead of/usr/bin
in your PATH). If you need compatibility with Bourne shells, check the man page on the systems you're interested in, as there have been many versions of sh with slightly different sets of features. Sven Mascheck maintains a page with a lot of information.