Avoid error with cat command when src file doesn't exist Avoid error with cat command when src file doesn't exist unix unix

Avoid error with cat command when src file doesn't exist


Test for file1 first.

[ -r file1 ] && cat ...

See help test for details.


elaborating on @Ignacio Vazquez-Abrams :

if (test -a file1); then cat file1 > file2; fi


File1 is emptyFile2 consists below contentpraveenNow I am trying to append the content of file1 to file2Since file1 is empty to nullifying error using /dev/null so output will not show any errorcat file1 >>file 2>/dev/nullFile2 content not got deletedfile2 content exsistspraveen If [ -f file1 ]thencat file  >> file2elsecat file1 >>file 2>/dev/nullfi