The ==
operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?
相关问题
- How to get the return code of a shell script in lu
- how to split a list into a given number of sub-lis
- Generate string from integer with arbitrary base i
- Converting a string array to a byte array
- Invoking Mirth Connect CLI with Powershell script
相关文章
- 使用2台跳板机的情况下如何使用scp传文件
- JSP String formatting Truncate
- In IntelliJ IDEA, how can I create a key binding t
- shell中反引号 `` 赋值变量问题
- How get the time in milliseconds in FreeBSD?
- Selecting only the first few characters in a strin
- Python: print in two columns
- Launch interactive SSH bash session from PHP
All of these answers ignore the easiest and quickest way to do this (as long as you have Bash 4):
All you're doing there is converting both strings to lowercase and comparing the results.
Very easy if you fgrep to do a case-insensitive line compare:
Same as answer from ghostdog74 but slightly different code
I came across this great blog/tutorial/whatever about dealing with case sensitive pattern. The following three methods are explained in details with examples:
1. Convert pattern to lowercase using tr command
2. Use regex with case patterns
3. Turn on nocasematch
For
zsh
the syntax is slightly different:This will convert
str2
to uppercase before the comparison.More examples for changing case below:
shopt -s nocaseglob