Using the [ command

A better-known form of the test command is the [ command. The primary difference between the two is that ] must be the last argument to [. This makes it look very much like a special syntax for shell script, but it isn't; it's just another command:

$ [ "$myshell" = 'bash' ] && printf 'Match!
'

Being a command, this syntax can be used after if, just like the grep and cd examples earlier in this chapter:

myshell=bash
if [ "$myshell" = 'bash' ] ; then
    printf 'Match!
'
fi

This is all specified by POSIX. Note that we still had to quote our variable to prevent special characters in its value from causing unwanted glob or whitespace expansion.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.197.49