如何测试一个字符串与另一个在bash开始? [英] How do I test if a string starts with another in bash?
问题描述
非常相似,但不重复: http://stackoverflow.com/a/2172367/57883
Very similar but not duplicate : http://stackoverflow.com/a/2172367/57883
我在Git中的Bash 3.1(至少是在提示时,我混帐的bash里面键入庆典即将到来的。
I'm in Git Bash 3.1 (at least that's what comes up in the prompt when I type bash inside git bash.
和 $测试[[DEV-0== D *] ||呼应「不及格」
打印失败。
如果[['DEV-0-1'== DEV *];然后回声是;
表示, [DEV-0-1:命令未找到
我想测试,如果的Git分支
返回的东西,与DEV开始。但我似乎无法适用答案。是不是因为我所有的尝试都使用字符串文字左侧,而不是一个变量的值?
if [['DEV-0-1' == DEV* ]]; then echo "yes";
says [[DEV-0-1: command not found
I'm trying to test if git branch
returns something that starts with DEV. but I can't seem to apply the answer. is it because all my attempts are using a string literal on the left instead of a variable value?
我也试图在ideone http://ideone.com/3IyEND
I've also tried it on ideone http://ideone.com/3IyEND
和没有运气。
它一直〜14岁,因为我是用好一个Linux提示。
and no luck. It's been ~14 years since I was good with a linux prompt.
我缺少一个字符串在bash测试开始?
What am I missing for a string starts with test in bash?
推荐答案
您错过了有空间:
if [[ 'DEV-0-1' == DEV* ]]; then echo "yes"; fi
^^
这篇关于如何测试一个字符串与另一个在bash开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!