Shorter way to assign a default value to the standard output stream
37 33 32 bytes
tr \ \\n|sort -n|sed s/^$/0/\;q
Edit: Saved 4 bytes thanks to @DigitalTrauma.
34 bytes
a=($(tr \ \\n|sort -n))
echo $[a]
The first line saves the sorted input values in an array a
.
This avoids using head -1
, since referencing the array as $a
will yield its first value.
The second line uses a
in the arithmetic expansion $[a]
. In this context, an empty string is interpreted as 0.
For a different default value, parameter substitution could be used instead. For example, the last line could become
echo ${a:-puppies}