3

I have the following set of commands in my script:

message="Secure copying file $remoteHost"
backupLogOutput "Info $message"
$(scp  "$file" "$remoteUser"@"$remoteHost":"$remotePath")  >> "$BACKUPLOG"
backupErrorHandler "$?" "$message"

ShellCheck is giving me the warning on the scp line (3):

Remove surrounding $() to avoid executing output. [SC2091]

The script works. I do want to execute the output. Shall I ignore this warning or should the scp line be written in a different way?

tomix86
  • 1,336
  • 2
  • 18
  • 29
AndyM
  • 562
  • 4
  • 22
  • 1
    the comments prevents for executing arbitrary output, indeed command between `$(..)` is like between backquotes, it is expanded to output, then the shell will split this output into command and arguments, try `$(echo "/bin/ls -l")` – Nahuel Fouilleul Dec 06 '17 at 15:29

1 Answers1

5

I don't think you actually do want to execute what scp outputs - it looks more like you simply want to copy a file:

scp  "$file" "$remoteUser"@"$remoteHost":"$remotePath"  >> "$BACKUPLOG"
Toby Speight
  • 27,591
  • 48
  • 66
  • 103