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
精彩评论