Search code examples
bashcurlheadercase-insensitivelowercase

Make the if statement case insensitive in bash


My code is going to check headers by using curl. Sometimes the headers and their values are shown with uppercase letters, sometimes with lowercase letters.

For example X-Requested-Id can be found like x-requested-id or X-Requested-ID.

How can I make the if statement case insensitive?

if [[ $check_headers == "X-Requested-Id"* ]]; then

Solution

  • With Bash 4 or newer, you can use a parameter expansion to lowercase the string:

    if [[ ${check_headers,,} == "x-requested-id"* ]]; then