AMC exec script: files with '(' in filename not working

Support for Ubuntu and other Desktop Linux distributions
Post Reply
lanrat
Posts: 4
Joined: 07 Sep 2021, 02:56

AMC exec script: files with '(' in filename not working

Post by lanrat »

Hello,

I'm using the filebot AMC script with the exec option. However I've found that when operating on files that have a '(' in their filename (as is common with movies for the year) then the '(' is treated like a shell command and an error is thrown. If I quote the file, then filebot gives an error, but it otherwise seems to work. Examples below:

When running filebot with:

Code: Select all

-script fn:amc --def exec="script.sh {file}"
Then filebot outputs:

Code: Select all

sh: 1: Syntax error: "(" unexpected
And script.sh is NOT called with the file.

If I add single quotes around the filename like:

Code: Select all

-script fn:amc --def exec="script.sh '{file}'"
Filebot outputs

Code: Select all

Bad exec value: script.sh '{file}'
but otherwise appears to work and the filename is arg1 ($1) in the script.

I don't understand why when not quoting the file filebot is treating the filename as a shell command. Is there a way to prevent this? Additionally, when quoting the file, why does filebot print an error? It seems unnecessary, as the script is still called correctly and everything seems to work as expected. Am I missing something?

Thanks.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: AMC exec script: files with '(' in filename not working

Post by rednoah »

1.
Does script.sh exist? Is it executable? Is it in the $PATH? Have you tried specifying the absolute path?


:idea: I'd start testing with commands that can't not work, and then take it from there:

Code: Select all

--def exec="echo '{f}'"
e.g.

Code: Select all

$ filebot -script fn:amc . --output /path/to/Media -non-strict --def exec="echo '{f}'"
...
[MOVE] from [Alias - S01E01.mp4] to [/path/to/Media/TV Shows/Alias/Season 01/Alias - S01E01 - Truth Be Told.mp4]
Processed 1 file
Execute: echo '/path/to/Media/TV Shows/Alias/Season 01/Alias - S01E01 - Truth Be Told.mp4'
/path/to/Media/TV Shows/Alias/Season 01/Alias - S01E01 - Truth Be Told.mp4


2.
rednoah wrote: 01 Aug 2012, 13:04 --def exec="echo {quote f}" Run program on newly processed files
The quote() helper function will help you quote argument values correctly for the value (which may contain ' itself) and underlying platform (bash and PowerShell quote arguments differently) at hand:

Code: Select all

--def exec="echo {quote f}"


EDIT:

lanrat wrote: 07 Sep 2021, 03:09 I don't understand why when not quoting the file filebot is treating the filename as a shell command.
:idea: --def exec allows you to generate generic shell commands (which may or may not pass a file path as $1) that FileBot then executes, as if you were typing it on the command-line. Please read Cmdline and Argument Passing for details.


Bad exec value: script.sh '{file}' is a misleading warning message in this case. It tries to detect and warn users about accidentally misquoted argument values. However, in your case, your argument is correct, but detected as false positive, yet also literally correct in a way because '...' indeed doesn't work for file paths with ' in them, albeit accidentally. :lol: It's just a warning that the amc script prints on startup, but has otherwise no effect and does not prevent your --def exec command from being called.
:idea: Please read the FAQ and How to Request Help.
lanrat
Posts: 4
Joined: 07 Sep 2021, 02:56

Re: AMC exec script: files with '(' in filename not working

Post by lanrat »

Thanks for the information.

script.sh is being provided a a full path and is called every time I run filebot. I have debugging information printed out when it runs to verify.

I tried using the quote function and changed the command to be:

Code: Select all

-script fn:amc --def exec="script.sh '{quote file}'"
But now the script does not appear to be called, and filebot prints out:

Code: Select all

Bad exec value: remux.sh '{quote file}'
sh: 1: Syntax error: "(" unexpected
Did I miss something?

Thanks.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: AMC exec script: files with '(' in filename not working

Post by rednoah »

e.g.

Code: Select all

--def exec="/path/to/remux.sh {quote f}"
:idea: quote() will quote the value for you as needed, and you must not add additional quotes.



:?: Are you not getting Execute: ... logging? The amc script prints each command verbatim before running it in a shell. That's the line you want to focus on.



GOOD: one ' before and after the argument value, this is what you want to see:

Code: Select all

Execute: /path/to/remux.sh '/path/to/file'
BAD: two consecutive ' in a row cancel each other out, and this is what happens when you use '...' in your command template, and use quote() to instruct FileBot to quote the value as well:

Code: Select all

Execute: /path/to/remux.sh ''/path/to/file''
:idea: Please read the FAQ and How to Request Help.
lanrat
Posts: 4
Joined: 07 Sep 2021, 02:56

Re: AMC exec script: files with '(' in filename not working

Post by lanrat »

Thanks, I'll try without the quotes:

Code: Select all

--def exec="remux.sh {quote file}" 

The first line of remux.sh prints $1, and some other information, so it is easy for me to tell when the script is running. However I've never seen the amc script print "Execute: ..." even when the script is run and I see the print statements from inside the script.

Does it matter if I use "{quote file}" vs "{quote f}"? Are 'file' and 'f' equivalent?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: AMC exec script: files with '(' in filename not working

Post by rednoah »

The amc script will print the commands generated by your --def exec option, unless you have explicitly specified a --log-level to reduce console output:
https://github.com/filebot/scripts/blob ... roovy#L485


:idea: f cannot be null, file can be null. They are equivalent in the context of --def exec because file is never null here.
:idea: Please read the FAQ and How to Request Help.
lanrat
Posts: 4
Joined: 07 Sep 2021, 02:56

Re: AMC exec script: files with '(' in filename not working

Post by lanrat »

Thanks for the help!

Using the following fixed all the errors:

Code: Select all

--def exec="remux.sh {quote file}"
Post Reply