开发者

One line condition in bash

I'm asked in my course HW to write a c开发者_如何学编程omparison in bash using just one line and without ';'. I am required to check whether the string in the variable 'fname' ends with the letter 'C', and if so to print "Match". There is no else command. how can I do it in one line?


Do you know of the &&, || and & command terminators in bash?

[[ "${fname:(-1)}" == "C" ]] && echo Match


I'm evil. I like being "clever":

echo ${fname}|sed -e 's/^.*\(.\)$/\1/' -e 's/[^C]/No /' -e 's/.$/Match/'

J

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜