In the bash script below, I check whether a file exists or not and then if it doesn't, I create it and write a simple snippet to it. It worked once(I don't know why), but I guess I have changed something and it's no more working, I can't find where's my mistake:
#...
template_file="~/mytest_template.c";
if [[ -z $template_file ]]; then
echo -e "#include <stdio.h>\n#include <stdlib.h>\n\n\nint main(int argc, char**argv){\n\n\t\n\nreturn 0;\n}" > ~/mytest_template.c;
fi
#sleep 0.5; ---> I tried this too.
cp ~/mytest_template.c mytest.c;
The error I get is this:
cp: cannot stat '/home/username/mytest_template.c': No such file or directory
Thanks.