Apostrophe terminated single quoted string High

When writing a string in single quotes, ensure that any apostrophes in the text do not prematurely terminate the string. To avoid this issue, either escape the apostrophes correctly or use double quotes for the string. This practice prevents syntax errors and maintains the integrity of the string.

Detector ID
shell/apostrophe-terminated-single-quoted-string@v1.0
Category
Common Weakness Enumeration (CWE) external icon
-
Tags
-

Noncompliant example

1
2# Noncompliant: Apostrophe terminates the string prematurely, causing a syntax error.
3echo 'I can't believe it's not butter!'

Compliant example

1
2# Compliant: Escaping the apostrophes allows them to be included in the single-quoted string.
3echo 'I can'\''t believe it'\''s not butter!'