Skip to content
Eisuke Kawashima edited this page Nov 8, 2023 · 3 revisions

In POSIX sh, $'..' is undefined.

Problematic code:

#!/bin/sh
IFS=$' \t\n'

Correct code:

#!/bin/sh
# Note: \n can not be last, or it will be stripped by $()
IFS=$(printf ' \n\t')

or

#!/bin/sh
# Trailing linefeed added literally
IFS="$(printf ' \t')
"

or

#!/bin/bash
# Bash supports this
IFS=$' \t\n'

Rationale:

ANSI-C quoting, $'..', is a bash extension, which is not supported by POSIX sh.

To ensure the script runs correctly on other systems, either switch to Bash, or rewrite it in a POSIX compatible way.

This can generally done via printf as in the example. Be careful about strings with trailing linefeeds, as a $(command substitution) will strip them.

Exceptions:

None.

Related resources:

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature guerraart8 to find a specific , or see Checks.

Clone this wiki locally