Today, there is a problem that needs to be judged whether there is a. c file in the directory. I used the IF [-f *.c], using the-F and wildcard characters to determine if there is a. c file, while Linux always complains "unexpected operator", so under-F, wildcard characters are not available later.
Later, I thought of a soil method, if [-n "' ls *.c '"], which means that if the LS command is executed, it is true, where-n indicates that the following content is not a null value. This sentence is available, you can determine the file exists in the directory, but this is a problem, if the directory does not have a. c file, it will be the error "No such files or directory", so I gave up this method.
A cow in the last QQ group told me, using if LS *.c >/dev/null 2>&1;then, this is a redirection method, ls all the file with. c suffix, if not, redirect standard error to standard output, here 2> &1 means that the standard error is also exported to the standard output. REDIRECT 0-standard output, 1-standard output, 2-standard error, and no such file or directory is a standard error.
Original address: http://www.tonitech.com/71.html