Skip to content

Files

Latest commit

 

History

History
25 lines (16 loc) · 475 Bytes

SC3057.md

File metadata and controls

25 lines (16 loc) · 475 Bytes

Pattern: Use of undefined string indexing

Issue: -

Description

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)"

Further Reading