0

rclone is a backup program I run from a bash script. I want to pass in this parameter to rclone:

--exclude "{secret1b,secret1c}/**"

rclone needs those quotes. Here is my failed attempt:

#!/bin/bash

cmd='rclone sync /home/wolfv/test_rclone_data/direc1 /home/wolfv/test_rclone_backup/last_snapshot/direc1 --exclude "{secret1b,secret1c}/**"'

printf "command: \n$cmd\n\n"
echo "$cmd"
#echo and printf output as expected:
#rclone sync /home/wolfv/test_rclone_data/direc1 /home/wolfv/test_rclone_backup/last_snapshot/direc1 --exclude "{secret1b,secret1c}/**"

#rclone with --exclude works as expected:
$(rclone sync /home/wolfv/test_rclone_data/direc1 /home/wolfv/test_rclone_backup/last_snapshot/direc1 --exclude "{secret1b,secret1c}/**")

#on these $cmd, rclone works but the --exclude is not excluding:
$cmd
$($cmd)

It's weird because the literal string output by echo "$cmd" works as expected.

$(rclone sync /home/wolfv/test_rclone_data/direc1 /home/wolfv/test_rclone_backup/last_snapshot/direc1 --exclude "{secret1b,secret1c}/**")

But the command $cmd does not work as expected.

$cmd

There are two similar questions that are NOT trying to pass in the quotes:

10
  • 2
    Don't put the command in a variable. See BashFAQ #50: "I'm trying to put a command in a variable, but the complex cases always fail!" Oh, and the two questions you linked both give valid answers to this. Commented Feb 9, 2018 at 5:56
  • did you try escaping the ". --exclude \"{secret1b,secret1c}/**\" Commented Feb 9, 2018 at 8:45
  • @abhishekphukan, making the quotes literal in that way completely changes the behavior from the original command (where they're syntactic). Moreover, the command that the OP is telling us works -- when they run the echo results as a shell command -- is a case where the quotes are syntactic (controlling how the shell divides argument lists) and not data (part of the individual argv elements passed to rclone). Commented Feb 9, 2018 at 19:47
  • @user2867994, you may think that you need to pass the quotes as literal data, but YOU ARE WRONG. If running the echo "$cmd" output works as expected when you copy-and-paste it back to a shell, then it's working with those quotes being parsed as syntax, not as data. Commented Feb 9, 2018 at 19:49
  • @user2867994, run set -x to tell the shell to log every command it runs, and compare the logs in that mode with the working command against those from your various attempts. Commented Feb 9, 2018 at 19:50

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.