Home Bug while checking for symbols inside of a string?
Reply: 0

Bug while checking for symbols inside of a string?

user805
1#
user805 Published in July 17, 2018, 11:26 pm

I'm creating a small calculator script and I've got stumbled on a strange bug. Everything seems to work but not when I input anything starting with (. When I do that if gives false and the code inside of else executes. I've tried a lot of ways rewriting how should "$input" =~ [-,+,*,/,\(,\)] look like but nothing worked. Do you have any idea why that's happening and how to solve this bug?

#!/bin/bash
read -p "Input: " input
if [[ ! "$input" =~ ^[A-Za-z_]+$ && "$input" =~ ^[0-9] && "$input" =~ [-,+,*,/,\(,\)] ]]; then
 (echo $input = $(($input))) 2>- || echo "Please, do not input ..."
else
 echo "Please, do not input letters or other special symbols and type in only expressions."
fi
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.382165 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO