Do not understand usage of --stdin-from-command

restic 0.17.0

help says

--stdin-from-command                     interpret arguments as command to execute and store its stdout
restic backup .... --stdin-from-command ls # works
restic backup .... --stdin-from-command ls -l # fails
restic backup .... --stdin-from-command "ls -l" # fails
restic backup .... --stdin-from-command ls --stdin-from-command "-l" # fails
restic backup .... --stdin-from-command ls --stdin-from-command /root # works!

The help text says arguments, so I would think more than one argument to --stdin-from-command is possible, but it does not seem so. Is it possible at all to pass arguments with leading “-” to the command, can you give a working example for bash?

Proposal for help text, adjusting to existing help texts (–password-command, --option)

--stdin-from-command command    execute command and store its stdout (can be specified several times for passing arguments)

And maybe a working example for something like “ls -l” in the documentation?

1 Like

Your shell Restic is interpreting parts of the command you supply as being part of the --stdin-from-command option rather than arguments to the restic command.

You need to use the -- notation to tell the shell where the options of the command end and the arguments start, so add -- after --stdin-from-command.

Clarifications have been added to the docs here: docs: clarify how to pass arguments using backup --stdin-from-command by MichaelEischer · Pull Request #4939 · restic/restic · GitHub

EDIT: It is not the shell, which I initially wrote, but the flag package in Go, and thereby restic, which interprets the options/flags/arguments and the --, as pointed out by @bernd.

3 Likes

Just to be precise, in this case the shell has nothing to do with interpreting the parts after --stdin-from-command. It’s restic itself that interprets the command line parts. The -- notation tells restic to stop grabbing additional command line parts as restic instructions.

1 Like

Thank you! I corrected my post on that.

1 Like