Re: Running from script - quotes being ignored?
"edgar.soldin--- via Duplicity-talk" <[email protected]>
| Newsgroups | gmane.comp.sysutils.backup.duplicity.general |
|---|---|
| Message-ID | <[email protected]> |
On 7/8/2025 8:59 AM, Andy Hairston via Duplicity-talk wrote:
> I'm sure this is more of a bash scripting issue, but I'm pretty well stuck. I've been running duplicity via bash scripts for several years, and went to add an option to specify compression level - and now the script won't work. Here's the script, minus some private items (and boiled down to just what is needed to reproduce the issue):
>
> export B2BUCKET=[snip]
> export DUPLICITY_CMD="pipx run duplicity"
> BACKUP_COMMAND="$DUPLICITY_CMD backup --gpg-options='--compress-algo=bzip2 --bzip2-compress-level=9'"
> echo -E $BACKUP_COMMAND /home/[snip] ${B2BUCKET}
> $BACKUP_COMMAND /home/[snip] ${B2BUCKET}
>
> If I run this, I get:
> pipx run duplicity backup --gpg-options='--compress-algo=bzip2 --bzip2-compress-level=9' /home/[snip] [snip]
> CommandLineError: Wrong number of positional args for 'backup', got 3
> Expected 2 positionals from ["--bzip2-compress-level=9'", '/home/[snip]', '[snip]'].
> Enter 'duplicity --help' for help screen.
>
> But if I copy the outputted line "pipx run duplicity ...", paste it into the command line, and run it, it runs fine. It's almost like the single-quotes around the gpg-options are being ignored, passing only the --compress-algo=bzip2 argument to gpg-options, and saving the bzip2-compress-level option for duplicity's backup command.
>
> I know I could put the entire thing on one line, but I had split it into command and arguments due to running multiple commands (remove-older-than, for instance). This works, and is my temporary workaround:
> $DUPLICITY_CMD backup --gpg-options='--compress-algo=bzip2 --bzip2-compress-level=9' /home/[snip] ${B2BUCKET}
>
> Any idea what I'm doing wrong in my export commands, causing the quotes to be ignored?
more a shell than a duplicity issue. read more here
https://stackoverflow.com/questions/59910932/bash-passing-parameters-to-a-c-program-via-shell-variable-how-to-deal-with-spa
tl;dr
either use `eval` e.g. `eval $BACKUP_COMMAND /home/[snip] ${B2BUCKET}`
or if you don't trust your own parameters
use bash and parse the string into a bash array and run that
```
declare -a command="( $BACKUP_COMMAND )"
"${command[@]}"
```
have fun.. ede/duply.net
_______________________________________________
Duplicity-talk mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/duplicity-talk