I am calling a script from a script and passing a positional argument {folder} — whose value is a path that contains spaces so it needs to be quoted.
The second script is:
#!/bin/bash -xu
find "$1" -type f -iname "*.srt" | grep -v -e "\\.eng" -e "].srt" -e "].[0-9].srt" | while read -r file; do trash -F "$file";done;
I have been unsuccessful in adding quotes around the path variable $1
. (I am guessing this is the issue, I would like to log all of the output to pinpoint it but not sure how to do that either)
I tried escaping it but that did not work \""$1"\"
The first script:
#!/bin/bash
filebot -exec /Users/john/.filebot/scripts/delete_non-english_subtitles.sh {folder}
The second script:
find "$1" -type f -iname "*.srt" | grep -v -e "\\.eng" -e "].srt" -e "].[0-9].srt" | while read -r file; do trash -F "$file";done; \
echo "$1" >> ~/Desktop/SsubDeletetest.txt; \
echo "$1" | awk -F"/" '{ print $NF }' >> ~/Desktop/subtitletest.txt; \
I added the echo lines to get an idea of how the argument value was formatted. Those two echo lines are working. There is output in those txt files. But the Find command never runs when called. I can run the same Find commands in terminal when I quote the path but argument apparently doesn't get quoted because at the first space in the path value the path is clipped.
I should add that the first script is being called by an application, not in Terminal. So the only way to see the results is to output to a text file... I think.
- Your post-process script is just deleting *.srt files, so that'd be a rather straight-forward -exec use case. You'll want to refactor that into it's own standalone script and then have filebot call it via -exec on the destination folder as explained above.
Here's what the call stack would look like:
1. qBT calls your qBT_e-program.sh 1.1. qBT_e-program.sh calls filebot 1.1.1. filebot -exec calls your delete-srt-files.sh passing along the destination {folder} as Argument $1 1.1.1.1. delete-srt-files.sh calls find "$1" ...```
Adding more to help troubleshoot. Still stuck on this. I learned how to get some output and have some clues but can't figure the issue out.
Again, When I add the path into the script instead of using the quoted variable "$1", the script works. When I use the variable it fails and results in this error output. This is being called from the initial script with quoted argument "{folder}". I have tried variations on treating the variable: "{$1}"
\""$1"\"
"$1/"
-$1
. I thought maybe the filebot -exec command was already quoting the variable and my quotes were actually unquoting it.
+ read -r file
find: /Volumes/PlexMedia/PlexServer_1/Movies/Paper: No such file or directory
find: Lives: No such file or directory
find: (2021)/Paper: No such file or directory
find: Lives: No such file or directory
find: (2021): No such file or directory
find: {imdb-tt13045890}: No such file or directory
find: [[en]: No such file or directory
find: 2.40∶1: No such file or directory
find: WS: No such file or directory
find: 1080p: No such file or directory
find: WEB-DL: No such file or directory
find: x265: No such file or directory
find: 584ECE9D].mp4: No such file or directory
echo result /Volumes/PlexMedia/PlexServer_1/Movies/Paper Lives (2021)/Paper Lives (2021) {imdb-tt13045890} [[en] 2.40∶1 WS 1080p WEB-DL x265 584ECE9D].mp4
I can see the variable is being split at the spaces. But it's quoted! This is a different file but same script calling it form Terminal:
Sat Mar 13 12:12:30
iMac191:Klara (2010) john$ /Users/john/.filebot/scripts/delete_non-english_subtitles.sh
+ path='/Volumes/PlexMedia/PlexServer_1/Movies/Test Folder (1968)'
+ find '/Volumes/PlexMedia/PlexServer_1/Movies/Test Folder (1968)' -type f -iname '*.srt'
+ grep -v -e '\.eng' -e '].srt' -e ']\.[0-9].srt'
+ read -r file
+ trash -F '/Volumes/PlexMedia/PlexServer_1/Movies/Test Folder (1968)/moviename.swe.srt'
+ read -r file
filebot
executable that gets passed to the next script.. although that may be my misunderstanding. I added the developers suggestion on how to write the script stack.