Today came across a good feature "-u" in shell. This will make the script to error when it comes across a undefined variable. If otherwise ,the undefined variable will expanded to nothing,
Running the script with "-u" option checks for the variables is not defined then throws the error "unbound variable"
Lets do it with a example,
$ cat t.sh
TEST=""
echo "Test"
echo $TEST
Running the script with "-u" option,
$ sh -u t.sh
Test
Now removing the Variable assignment and running the script,
$ cat t.sh
echo "Test"
echo $TEST
Running the script with "-u" option checks for the variables is not defined then throws the error "unbound variable"
Lets do it with a example,
$ cat t.sh
TEST=""
echo "Test"
echo $TEST
Running the script with "-u" option,
$ sh -u t.sh
Test
Now removing the Variable assignment and running the script,
$ cat t.sh
echo "Test"
echo $TEST
$ sh -u t.sh
Test
t.sh: line 5: TEST: unbound variable
No comments:
Post a Comment