0

The folder "/tmp/folder" contains one file, whose filename consists only of a single newline.

The output of ls -A /tmp/folder, even inside a non-interactive script, is:

''$'\n'

Here are the contents of script.sh:

#!/bin/sh --

var="$(ls -A /tmp/folder; printf x)"

var="${var%x}"

printf '%s' "$var"

The output of script.sh is two empty lines.

Maybe GNU ls can detect if it is being run inside of a command substitution or is being redirected to file?

0 Answers0