Pattern: Use of undefined string indexing
Issue: -
String indexing is a bash and ksh extension, and does not work in dash
or POSIX sh
.
Example of incorrect code:
#!/bin/sh
echo "Your initial is ${USER:0:1}"
Example of correct code:
#!/bin/sh
echo "Your initial is $(printf '%s' "$USER" | cut -c 1)"