如何测试小于或等于Bash中的字典顺序的字符串? [英] How to test strings for lexicographic less than or equal in Bash?

查看:87
本文介绍了如何测试小于或等于Bash中的字典顺序的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Bash中,有没有一种简单的方法来测试一个字符串在字典上是否小于或等于另一个字符串?

In Bash, is there a simple way to test if one string is lexicographically less than or equal to another?

我知道你可以做到:

if [[ "a" < "b" ]]

用于测试严格的不平等,或

for testing strict inequality, or

if [[ 1 -le 1 ]]

获取数字.但是-le似乎不适用于字符串,并且使用<=会产生语法错误.

for numbers. But -le doesn't seem to work with strings, and using <= gives a syntax error.

推荐答案

只抵消大于测试的值:

if [[ ! "a" > "b" ]]

这篇关于如何测试小于或等于Bash中的字典顺序的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆