The issue is that tilde expansion
will not happen as the path is in a variable value (tilde expansion
happens before variable expansion
). You can ameliorate this issue by using $HOME
instead of ~
. That is
target_file="${HOME}/${source_file}"
This should solve your problem.
Further reading: EXPANSION
section of man bash