Skip to content

[SC3045] read -d is POSIX.1-2024 compliant #3062

@JP-Ellis

Description

@JP-Ellis

For bugs

  • Rule Id: SC3045
  • My shellcheck version (shellcheck --version or 'online'): online
  • I tried on shellcheck.net and verified that this is still a problem on the latest commit

For new checks and feature suggestions

Here's a snippet or screenshot that shows the problem:

#!/bin/sh

read -r -d ':' foo

Here's what shellcheck currently says:

Line 3	SC3045: In POSIX sh, read -d is undefined.

Here's what I wanted or expected to see:

I believe this is a false-positive, as the POSIX description for read shows that it does support -d. See the specification here and the relevant quote part below.

NAME

read — read from standard input into shell variables

SYNOPSIS

read [-r] [-d delim] var...

OPTIONS

The read utility shall conform to XBD 12.2 Utility Syntax Guidelines .

The following options shall be supported:

  • -d delim

    If delim consists of one single-byte character, that byte shall be used as the logical line delimiter. If delim is the null string, the logical line delimiter shall be the null byte. Otherwise, the behavior is unspecified.

  • -r

    Do not treat a character in any special way. Consider each to be part of the input line.

The support for -d in POSIX appears to be relatively recent though, as the previous edition do indeed omit it the option.

Perhaps I missed a way of specifying the POSIX version?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions