⭑⭑ Use the @file syntax for reading command-line arguments from external text files so you don't have to worry about any of this. ;) ⭑⭑
Argument Parsing
When calling cmdline tools you first specify the command followed by arguments separated by space. In order to call a command by name without specifying the full path to the executable it needs to be in the PATH (by adding the folder where the executable is %PATH% on Windows, or by symlinking to /usr/bin on Linux/Mac).e.g. command: filebot, args: [-version]
Shell: Select all
filebot -version
Quote Arguments
If you want to pass an argument that itself contains spaces then you need to quote the value with "x"command: C:/Program Files/FileBot/filebot.exe:, args: [-rename, D:/New Files]
Shell: Select all
"C:/Program Files/FileBot/filebot.exe" -rename "D:/New Files"
e.g. calling rm -r /New Media will remove the folder /New as well as the folder ./Media (path relative to the current working directory)
BAD command: filebot:, args: [-rename, D:/New, C:/Program Files/FileBot/Files]
Shell: Select all
filebot -rename D:/New Files
Avoid non-ASCII characters
Never use non-ASCII characters like “ or ” and note that these characters are not the same as the " standard quotation mark. If a character is not on the keyboard, then it will not have any special meaning on the command-line.command: echo, args: [Hello World]
Console Output: Select all
$ echo "Hello World"
Hello World
BAD command: echo, args: [“Hello, World”]
Console Output: Select all
$ echo “Hello Hello”
“Hello Hello”
Escape Arguments
If you want to pass an argument that itself contains double-quotes or other special characters that are interpreted by the shell (e.g. * or $ or ! in bash) you may need to further escape these characters with \x.Escaping arguments correctly is mostly a matter of trial and error. See the following examples to get a feeling for how it works:
How to quote:
Console Output: Select all
$ echo "How to \"quote\""
How to "quote"
How NOT to quote:
Console Output: Select all
$ echo "How to "quote""
How to quote
$variables will be resolved:
Console Output: Select all
$ echo "I like $TEST"
I like
Console Output: Select all
$ echo "I like \$TEST"
I like $TEST
! is expanded to a previously used command or an event not found error:
Console Output: Select all
$ echo "!bash"
!bash: event not found
$ bash -c 'echo Hello'
Hello
$ echo "!bash"
echo "bash -c 'echo Hello'"
bash -c 'echo Hello'
Shell expansion (i.e. implicitly pass in multiple arguments):
Console Output: Select all
$ echo *.mp4
firefly.101.mp4
Avoid shell expansion using escaping:
Console Output: Select all
$ echo \*.mp4
*.mp4
Avoid shell expansion using quoting:
Console Output: Select all
$ echo "*.mp4"
*.mp4
Troubleshooting
If arguments don't get passed as expected, just use trial and error to find the problem. Just break things down step by step and see what works as expected and what does not work as expected.It helps to see what is actually passed on to the application. Here's a script for that:
Shell: Select all
filebot -script fn:sysenv arg1 arg2 ...
Console Output: Select all
$ filebot -script fn:sysenv Hello World
...
args[0] = -script
args[1] = fn:sysenv
args[2] = Hello
args[3] = World
Console Output: Select all
$ filebot -script fn:sysenv "Hello World"
...
args[0] = -script
args[1] = fn:sysenv
args[2] = Hello World