The problem is that tilde expansion does not happen because the path is in a variable value ( tilde expansion occurs before variable expansion ). You can improve this problem by using $HOME instead of ~ . it
target_file="${HOME}/${source_file}"
This should solve your problem.
Further reading: EXPANSION section man bash
source share