Checking BASH strings in while loops for single quotes?
Looking to check if a string doesn't contain single quotes in the following syntax, 'text' (although it could also be 'text','text','text') but haven't been able to escape the quotes properly as to allow the opening of a while loop. Code:
while [[ -z "$projects" ]] || [[ "$projects" =~ *"'" ]]; do
<reprompt user, read var, and reset variable>
done
The above is the best I've dreamt up, but it only looks for an ending ', and doesn't even work properly at that as testing with "a" does not result in entering the loop. How should I be testing for badly formatted user strings when single-quotes come into play?
Looks like what I ended up needing was:
while [[ "$projects" != "'"?*"'" ]];do
This will catch null values and ensures that there is at least one character in between the single quotes.
链接地址: http://www.djcxy.com/p/9802.html