0

I'm trying to call arguments for running a script with the rsync command. I've tried various forms and this is the most "simple", however I continue to get an error.

(bash.sh)

#! /bin/bash
root_dir = $1
target_dir = $2
rsync -avh -P --stats $root_dir $target_dir
echo "Files Transferred!"

ErrorMessage

test.sh: line 2: root_dir: command not found
test.sh: line 3: target_dir: command not found

Command Line

sh bash.sh ./path_root_dir ./path_target_dir
mkrieger1
  • 19,194
  • 5
  • 54
  • 65

1 Answers1

-1

Using a variable with a space, without using speech marks or a quote on each side can cause an error to occur, especially when the variable is used and there was a space in the value.

Another way you could try is to use an array, the options variable is where the array is, and then it is called in the rsync command below,

directory="/etc"
backupDirectory="/backup"
incrementalBackup="/incremental"
options=(-a -e 'ssh -p 10022' -b --backup-dir="$incrementalBackup" --delete)
# rsync
rsync "${options[@]}" user@server:"$directory" "$backupDirectory"
Shaqil Ismail
  • 1,794
  • 1
  • 4
  • 5