Rather than:
if [ "" = "$var" ]; then
$var=hello
fi
Use
var=${var:-hello}
Conversely, rather than:
if [ "" != "$var" ]; then
$var=hello
fi
Use
var=${var:+hello}
There's also:
if [ "" = "$var" ]; then
echo "Error, variable var must be set"
else
b=$var
fi
And:
b=${var:?Error, variable var must be set}
There are others too, but I find these ones most useful. Check bash man page for full set.
No comments:
Post a Comment