Richard Barraclough
Richard Barraclough

Reputation: 2994

If or ternary operator in bc

I want to write

level=$( echo "scale=0; ( 254 * ( if ( $1 > 100 ) { 100 } else { $1 } ) ) / 100" | bc )

but it appears to be impossible. Is this so?

Upvotes: -1

Views: 39

Answers (1)

Richard Barraclough
Richard Barraclough

Reputation: 2994

Use awk instead:

awk "BEGIN { if ( $h < 13 ) { print 13 - $h } else { print 1 }; exit }"

Upvotes: -1

Related Questions