From 77222684890cca694857759a51fd4c74ddb31821 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Fri, 11 Apr 2025 15:25:41 -0700 Subject: [PATCH] Created SC3064 (markdown) --- SC3064.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 SC3064.md diff --git a/SC3064.md b/SC3064.md new file mode 100644 index 0000000..3d1836a --- /dev/null +++ b/SC3064.md @@ -0,0 +1,32 @@ +## In POSIX sh, test -N is undefined. + +### Problematic code: + +```sh +if [ -N file ] +then + echo "File has been modified since last read" +fi +``` + +### Correct code: + +```sh +if bash -c '[ -N file ]' +then + echo "File has been modified since last read" +fi +``` +### Rationale: + +`test -N` is not supported by POSIX, and there is no straight forward way of simulating it. If you need this functionality, look into which non-POSIX features your system has to allow this. `stat -c`, `find -printf`, bash, ksh, and Python are all possible options. + +Note that `atime` did not turn out to be as useful as first imagined in 1970, and it's generally better not to rely on it. + +### Exceptions: + +None. If you expect your shell to support `test -N`, either explicitly specify it in the shebang, use a `# shellcheck shell=bash` directive, or ignore this warning. + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc! \ No newline at end of file