It gives an error in the second line, although in the terminal the same command works fine. Please see what is wrong. Here is the script itself:

#!/bin/bash echo удалить файлы \: `find !(*.cpp) -maxdepth 0` \? read -n 1 x while( [ "$x" -ne "y" && "$x" -ne "n" ] ) do if [[ "$x" -eq "y" ]] then rm `find !(*.cpp) -maxdepth 0` else if [[ "$x" -ne "n" ]] then echo введён неверный символ, повторите ввод read -n 1 x if done 

    1 answer 1

    As it is all difficult, you can make it easier

     find . -type f | sed "/\.cpp/d" | xargs rm -f 

    It's easy to delete all files without confirmation.

    • Less payp, more profit: find <path> -type f ! -name '*.cpp' -exec rm -f {} \; find <path> -type f ! -name '*.cpp' -exec rm -f {} \; - approximatenumber
    • Yes, it's more beautiful - Yaroslav
    • Thank you, but still I would like to know what the error in my script is, I just started studying bash and I’m interested to deal with its conditional operators and cycles - Fexolm
    • find! ( .cpp) -maxdepth 0. more correctly find. ! -name " .cpp" -maxdepth 0. - Yaroslav
    • Thank you, could you tell me what the points mean in this case? - Fexolm