BASH shell scripting tip: Set default values for variable

Filed under
HowTos

A shell variable may be assigned to by a statement using following syntax:
var=value If value is not given, the variable is assigned the null string. In shell program it is quite useful to provide default value for variables.

For example consider rsync.sh script:

#!/bin/bash
RSRC=$1
LOCAL=$2
rsync -avz -e ’ssh ‘ user@myserver:$RSRC $LOCAL

This script can be run as follows:

More Here.