Skip to content

Files

Latest commit

 

History

History
29 lines (17 loc) · 712 Bytes

SC2268.md

File metadata and controls

29 lines (17 loc) · 712 Bytes

Pattern: Use of x-prefix in comparison

Issue: -

Description

Some older shells would get confused if the first argument started with a dash, or consisted of ! or (. As a workaround, people would prefix variables and values to be compared with x to ensure the left-hand side always started with an alphanumeric character.

POSIX ensures this is not necessary, and all modern shells now follow suite.

Example of incorrect code:

[ "x$pass" = "xswordfish" ]

test x"$var" = x 

Example of correct code:

[ "$pass" = "swordfish" ] 

test "$var" = ""

Further Reading