Get rid of the leading dollar sign.
statementResult=$($statement)
I also encourage you to store commands in functions rather than in variables.
statement() {
rsync -avzh --progress ./GGERPTTESTINGSANDBOX/source_folder/ ./GGERPTTESTINGSANDBOX/target_folder/
}
statementResult=$(statement)
Functions can take parameters, making it easy to invoke a pre-defined command with different arguments. When their parameters are properly quoted they can handle file names with spaces and other unusual--but permitted--characters.
For example, you could parameterize your function so it just does the rsync
and leaves the path names up to the caller:
synchronize() {
local dir=$1
local src=$2
local dest=$3
rsync -avzh --progress "$dir/$src/" "$dir/$dest/"
}
result=$(synchronize ./GGERPTTESTINGSANDBOX source_folder target_folder)
result=$(synchronize ./GGERPTTESTINGSANDBOX 'from here' 'to here')
Notice how this accepts directory names with spaces (from here
and to here
). That would be very difficult to do with a variable holding the same code.