I am trying to test if a file fails to transfer using SCP.

I noticed if I use a **un-initialized variable**, I get exit 0 even though the SCP fails.

For example, I have an empty variable called **uninitialized\_var**

```

[root@centos_8_0 scripts]# echo $uninitialized_var

```

If I try to use it in SCP command, the command appears to work, returns exit 0, however no file is copied due to non-existent path. If I use a hard path that does not exist, it will fail.

```

[root@centos_8_0 scripts]# scp root@centos_8_1:/root/test/stack_test/file_20210302.csv $uninitialized_var/file_20210302.csv
file_20210302.csv                                                                                                                                                     100%    0     0.0KB/s   00:00

```

```

[root@centos_8_0 scripts]# echo $?
0

```

Is there a way to test if copy succeeded? Currently I am using:

```

if [[ $? != 0 ]]; then... 
however like I said it returns 0.

```

Is there a reason why it returns 0?