SCP exit 0 when using un-initialized variable and fail to copy

Solution 1:

The variable will be expanded by the shell and in this case prepended to /file_20210302.csv. This means that your destination path is just /file_20210302.csv. You are performing this action as root which has write permission to /. The files are being copied and placed in your root directory, no error is occurring so the exit status is 0.

I tested this with

scp [email protected]:/home/user/test_file  $uninitialized_var/tmp/test_file

and it worked as expected, placed the file in /tmp and exit status 0.