开发者

One line condition in bash

开发者 https://www.devze.com 2023-01-23 06:54 出处:网络
I\'m asked in my course HW to write a c开发者_如何学编程omparison in bash using just one line and without \';\'.

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

精彩评论

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