I am trying to test rm
on a list of quoted filenames, and it will not work. Here's a screenshot of the very simple demo macro:
Screenshot
(There's a space in the Replace line of the regex that finds ⌃R.)
I build a list of filenames, each in quotes and separated by a space. I then ask rm
to remove those files, via this:
rm "/full/path/to/file 1" "/full/path/to/file 2" etc
But it fails; here's the error log:
2023-10-12 07:52:41 Action 15043653 failed: Execute a Shell Script failed with script error: rm: "/Users/robg/Desktop/temp/file 1" "/Users/robg/Desktop/temp/file 4" "/Users/robg/Desktop/temp/file 5": No such file or directory
And yet, if I do the exact same thing in Terminal, it works:
rm multi line var.kmmacros (4.4 KB)
What am I doing wrong?
-rob.
(And I realize I could do this with a looping shell script, but it really should work on one command line.)
-rob.
Does it fail if you include the file extensions in the paths?
There are no file extensions—I just touched files "file 1" to "file 10." And I've tried with an without the quotes on the shell script line. With a quoted quote. With filter for shell quotes. Nada.
It seems the shell is seeing the KM variable as one value, instead of a set of names, which I guess means I'll have to do the loop thing :(.
-rob.
rm /Users/noisyneil/Desktop/test1.txt /Users/noisyneil/Desktop/test2.txt
Works for me.
In shell directly or in a test macro? If so, can you post the macro?
-rob.
Also, put a space in the filename; I think that's a big part of the problem.
-rob.
I tried escaping the spaces now, and it still errors out, but it shows how the space is causing problems:
2023-10-12 08:36:56 Action 15043653 failed: Execute a Shell Script failed with script error: rm: "/Users/robg/Desktop/temp/file\: No such file or directory
rm: 1".txt: No such file or directory
rm: "/Users/robg/Desktop/temp/file\: No such file or directory
rm: 4".txt: No such file or directory
rm: "/Users/robg/Desktop/temp/file\: No such file or directory
rm: 5".txt: No such file or directory
2023-10-12 08:36:56 Execute a Shell Script failed with script error: rm: "/Users/robg/Desktop/temp/file\: No such file or directory
rm: 1".txt: No such file or directory
rm: "/Users/robg/Desktop/temp/file\: No such file or directory
rm: 4".txt: No such file or directory
rm: "/Users/robg/Desktop/temp/file\: No such file or directory
rm: 5".txt: No such file or directory. Macro “rm multi line var” cancelled (while executing Execute Shell Script).
If I enclose it all in quotes in the shell script call, then I get a one liner error:
2023-10-12 08:40:08 Execute a Shell Script failed with script error: rm: "/Users/robg/Desktop/temp/file\ 1" "/Users/robg/Desktop/temp/file\ 4" "/Users/robg/Desktop/temp/file\ 5": No such file or directory. Macro “rm multi line var” cancelled (while executing Execute Shell Script).
-rob.
I've had to pop out for an hour. Will investigate when I'm back.
Even without spaces, I can't get the script to work:
2023-10-12 08:44:00 Execute a Shell Script failed with script error: rm: "/Users/robg/Desktop/temp/file1": No such file or directory
rm: "/Users/robg/Desktop/temp/file4": No such file or directory
rm: "/Users/robg/Desktop/temp/file5": No such file or directory. Macro “rm multi line var” cancelled (while executing Execute Shell Script).
I am stumped.
In the end, I gave up and used a loop:
#!/bin/bash
files_to_delete="$KMVAR_local_theData"
IFS=""
while IFS= read -r file; do
rm "$file"
done <<< "$files_to_delete"
(I don't do any checks on whether the file exists first because the list is built only from files that do exist.)
My lists are relatively short, so running rm
a few times in a row isn't a huge time hit. I'd still like to know why the other method doesn't work, though.
-rob.
Here's a recent post from Peter on this very topic.
1 Like