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?
lsdetect ..."? – Kusalananda Feb 02 '20 at 07:06lsdetect..."? Thanks @muru for pointing me to the right answer – Harold Fischer Feb 02 '20 at 07:07