|
From: Jef P. <je...@ma...> - 2016-07-28 22:50:38
|
>What's the purpose of the 'x' in lines like these? > >if [ "x$2" = "x6" ]; then > >Since the string literals are provided, there shouldn't be an error when >the provided strings are empty. Isn't the 'x' there to guard against an >empty string? That's a common idiom in shell script programming. It's to guard against the string being check having a flag argument that the [ command, a.k.a. test, would interpret. This is really due to test having poorly thought out argument syntax but what are you gonna do. Another common idiom is to merely reverse the order of the strings being checked: if [ "6" = "$2" ]; then Putting the variable second means test won't try to interpret it as a flag. |