本文介绍了检查Bash中的字符串包含斜杠还是反斜杠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我当前正在尝试获取bash脚本,以检查字符串是否包含"/" 或"\"
I'm currently trying to get my bash script checking if a string containts a "/" or a "\" but somehow I can't get it working.
这是我到目前为止所得到的:
Here is what I got so far:
if [[ "$1" == *\/* ]]; then ... elif if [[ "$1" == *\\* ]]; then ... fi非常感谢您的帮助!谢谢
Help is much appreciated! Thanks
推荐答案这将检查 \ 或/是否在变量 $ string .
This checks if either \ or / are in the variable $string.
if [[ "$string" == *\/* ]] || [[ "$string" == *\\* ]] then echo "yes" fi测试:
$ string="hello" $ if [[ "$string" == *\/* ]] || [[ "$string" == *\\* ]]; then echo "yes"; fi $ $ string="hel\lo" $ if [[ "$string" == *\/* ]] || [[ "$string" == *\\* ]]; then echo "yes"; fi yes $ string="hel//lo" $ if [[ "$string" == *\/* ]] || [[ "$string" == *\\* ]]; then echo "yes"; fi yes更多推荐
检查Bash中的字符串包含斜杠还是反斜杠?
发布评论