Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

One line condition in bash

Tags:

bash

I'm asked in my course HW to write a comparison 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?

like image 876
SIMEL Avatar asked Nov 02 '10 09:11

SIMEL


1 Answers

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

[[ "${fname:(-1)}" == "C" ]] && echo Match
like image 117
Benoit Avatar answered Sep 28 '22 05:09

Benoit