I'm coding a very simple shell that deletes files of a given folder, in this case all .csv files that lives in that folder.
The code looks like this:
#!/bin/bash # Used to clean folder MinVal=0 Files=$(ls -1 *.csv | wc -l) if [ $Files -gt $MinVal ];then rm *.csv echo -e "\e[31;43m***** DONE *****\e[0m" else echo -e "\e[31;43mThere is no valid file to delete, please check\e[0m" fi
The shell script works as expected, but when you execute the shell and there is no .csv files in the folder the terminal says the following:
ls: cannot access *.csv: No such file or directory
off course it also shows the
There is no valid file to delete, please check
Is there any way to avoid the
ls: cannot access *.csv: No such file or directory and get straight to the to the
else error handling?