Linux shell编程字符串比较语法 [英] Linux shell programming string compare syntax

查看:139
本文介绍了Linux shell编程字符串比较语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

= == 之间有什么区别来比较Linux shell编程中的字符串?

What is the difference between = and == to compare strings in Linux shell programming?

也许下面的代码可以工作:

Maybe the following code works:

if [ "$NAME" = "user" ]
then
    echo "your name is user"
fi

但我认为这不是一个正确的语法。它将用于比较 == 语句的字符串。

But I think it's not a correct syntax. It would be used to compare string by == statement.

什么是正确的?

推荐答案

Googlebash compare strings: http://www.google.com/search?q=bash%20compare%20字符

Google "bash compare strings": http://www.google.com/search?q=bash%20compare%20strings

  • http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/
  • http://tldp.org/LDP/abs/html/comparison-ops.html
  • http://www.faqs.org/docs/Linux-HOWTO/Bash-Prog-Intro-HOWTO.html#ss11.2

这不难吗?

我链接的第二页,你会发现:

Also, as on the second page I linked, you will find:

==

    is equal to

    if [ "$a" == "$b" ]

    This is a synonym for =.

这篇关于Linux shell编程字符串比较语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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