You need to use 2> , not >2 to redirect the standard error.
touch "$file" 2> /dev/null
But even with this change, your script has an error:
Suppose touch fails because the file exists, but you do not have permission to touch it. Then you check if the file exists using the -e check, which returns true , and you print File created , which is incorrect.
To fix this, you need to check the return value of the touch command as:
if touch "$file" 2> /dev/null ; then echo "..........File created" else echo "..........File failed"
source share