tumbleweed 20260219
linux v6.19.2-1-default x86_64
I am writing a script to show the usage of all of the files and directories starting in a specified directory using du.
The issue is providing all of the directories and files for input to du. If any of the names have spaces in the name, du does not parse the name correctly. The script is shown below.
du is fed the list: 'du -sh '2025-07-15 16-51-37.mkv' '2025-07-15 16-52-43.mkv'
Note the single quotes. When run from the command line, there is no issue.
$ du -sh '2025-07-15 16-51-37.mkv' '2025-07-15 16-52-43.mkv'
du: cannot access "'2025-07-15": No such file or directory
du: cannot access "16-51-37.mkv'": No such file or directory
du: cannot access "'2025-07-15": No such file or directory
du: cannot access "16-52-43.mkv'": No such file or directory
The single quotes are ignored and spaces are treated as an argument separator.
You may want to provide informations about your hidden script. Both your terminal output from bash and your script invoke the same command. The help you recieve depends on the information you provide.
But there is no script posted to see what exactly is there, nor as a start for others to re-create and experiment.
Thus, please post a minimal script that shows your problem.
They most probably are not, but are already interpreted by the script before the command itself is interpreted.
bash -x t.sh
+ cmd='du -hs'
+ basedir=.
++ /usr/bin/ls --quoting-style=shell-escape ./
+ dlst=''\''2025-07-15 16-51-37.mkv'\''
'\''2025-07-15 16-52-43.mkv'\''
t.sh'
+ txt='du -hs '\''2025-07-15 16-51-37.mkv'\''
'\''2025-07-15 16-52-43.mkv'\''
t.sh'
+ echo du -hs ''\''2025-07-15' '16-51-37.mkv'\''' ''\''2025-07-15' '16-52-43.mkv'\''' t.sh
du -hs '2025-07-15 16-51-37.mkv' '2025-07-15 16-52-43.mkv' t.sh
+ du -hs ''\''2025-07-15' '16-51-37.mkv'\''' ''\''2025-07-15' '16-52-43.mkv'\''' t.sh
du: Zugriff auf "'2025-07-15" nicht möglich: Datei oder Verzeichnis nicht gefunden
du: Zugriff auf "16-51-37.mkv'" nicht möglich: Datei oder Verzeichnis nicht gefunden
du: Zugriff auf "'2025-07-15" nicht möglich: Datei oder Verzeichnis nicht gefunden
du: Zugriff auf "16-52-43.mkv'" nicht möglich: Datei oder Verzeichnis nicht gefunden
4,0K t.sh
you can see that the escapes are used and consumed in line
as mentioned above. Even though I make the mistake myself from time to time, it’s never a good idea to use ls in a script. You could use an array instead
# Get a list of files/directories for device usage
# Use xargs to preserve the escaping.
#
$basedir="$1"
dlst=$(/usr/bin/ls --quoting-style=shell-escape $basedir)
echo $dlst | xargs $cmd