Pages

Friday, November 16, 2012

Conditional variable assignment/ substitution


Bash does support the conditional variable assignment/ substitution e.g.  below code snippet

#! /bin/bash

name=${2:-"Juned"}

if [ "$name" != "Juned" ];then
echo  "hello $name"
else
echo "bye"
fi

will define the variable name with second command line parameter , but if there is no second command line parameter then the name is defaulted to Juned

No comments:

Post a Comment