Unix Shell: use default value if variable not set 

Joined:
04/09/2007
Posts:
784

September 29, 2008 03:22:07    Last update: September 29, 2008 03:22:35
Use shell expression: ${MYVAR:-my_default}: the value is $MYVAR if MYVAR is defined, otherwise the value is "my_default".

The following expression means use $FCEDIT if defined, otherwise try $EDITOR, if $EDITOR is not defined either, use vi:
${FCEDIT:-${EDITOR:-vi}}
Share |
| Comment  | Tags