Find the answer to your Linux question:
Results 1 to 4 of 4
How would I check if a string doesn't say "y" or "yes" no matter what the cases of the letters are? Right now I've: Code: if [ ! "$dl" == ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Engineer
    Join Date
    Jan 2005
    Location
    Chicago (USA)
    Posts
    1,028

    Checking string no matter the case in Bourne Shell


    How would I check if a string doesn't say "y" or "yes" no matter what the cases of the letters are? Right now I've:
    Code:
    if [ ! "$dl" == "[Y,y]" ] || [ ! "$dl" == "[Y,y][E,e][S,s]" ]; then

  2. #2
    Banned CodeRoot's Avatar
    Join Date
    Sep 2005
    Posts
    567
    One possible way:

    Code:
    testdata=`echo "$dl" | tr "a-z" "A-Z"`
    if [ "$testdata" != "Y" ] && [ "$testdata" != "YES" ]; then

  3. #3
    Linux Engineer
    Join Date
    Jan 2005
    Location
    Chicago (USA)
    Posts
    1,028
    Thanks, that works.

  4. #4
    Banned CodeRoot's Avatar
    Join Date
    Sep 2005
    Posts
    567
    Your welcome -- glad I could be of service...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •