0

I have an rsync command that works as expected when I type it directly into a terminal. The command includes several --include='blah' and --exclude='foo' type arguments. However, if I save that command to a one-line file called "myfile" and I try `cat myfile` (or, equivalently $(cat myfile)), the rsync command behaves differently.

I'm sure it is the exact same command in both cases.

Is this behavior expected/explainable?

n3utrino
  • 1,160
  • 1
  • 8
  • 16
  • 1
    Quoting/quote removal and word-splitting. Run `set -x` before you run both versions of the command to see the difference. – Etan Reisner May 18 '15 at 17:56
  • 1
    Whatever you are trying, `$(cat myfile)` is a wretched way to attempt to do it. The dot (aka `source` in Bash) evaluates the commands in a file in the context of the current shell, if that is what you want to accomplish. So just say `. myfile` instead. – tripleee May 18 '15 at 18:15

1 Answers1

0

I've found the answer to this question. The point is that the cat command takes the contents of the file and treats it like a string. Any string operators (like the escape operator, ) are executed. Then, the final string output is what is passed to a command via the backticks.

As a solution, I've just made "myfile" a shell script that I can execute rather than trying to use cat.

n3utrino
  • 1,160
  • 1
  • 8
  • 16