if [ '`echo "$url" | grep (\.tar\.gz|\.tar\.bz2|\.zip|\.rar|\.7z)$`' ] ; then
syntax error, I just want to check file extension.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First of all, you need to remove the
''as otherwise the test is just a string that always evaluates to true. You need to put the regex in quotes as parentheses are interpreted by bash. You also need to useegrep(equivalent togrep -E).You can also shorten the regex by factoring the
.out of the group and groupingtar.{gz,bz2}:For future, please take note of the error bash gives you which tells you quite a lot:
bash: syntax error near unexpected token (suggests that the error is around the(, which I’ve just shown you is exactly where the error lies.Jonathan’s answer offers more tips on improving the test.