n=3
#1.1. assgin value using ternary assignment
s="I have $n `[ $n -eq 1 ] && echo apple || echo apples`"; echo $s
#2.2. print value with ternary assignment
echo "I have $n `[ $n -eq 1 ] && echo apple || echo apples`"
printf "I have %d %s\n" $n `[ $n -eq 1 ] && echo apple || echo apples`
-------output----------
#1.1. assgin value using ternary assignment
I have 3 apples
#2.2. print value with ternary assignment
I have 3 apples
I have 3 apples
|
$n=3;
#1.1. assgin value using ternary assignment
$s = "I have $n ".(($n==1)? "apple": "apples");print "$s\n";
#2.2. print value with ternary assignment
print "I have $n ".(($n==1)? "apple": "apples")."\n";
printf "I have %d %s.\n", $n, ($n == 1) ? "apple" : "apples";
-------output----------
#1.1. assgin value using ternary assignment
I have 3 apples
#2.2. print value with ternary assignment
I have 3 apples
I have 3 apples.
|
n=3
#1.1. assgin value using ternary assignment
s="I have "+str(n)+(" apple" if n==1 else " apples")
print s
#2.2. print value with ternary assignment
print "I have", n, "apple" if n==1 else "apples"
print "I have %d %s" % (n, "apple" if n==1 else "apples")
-------output----------
#1.1. assgin value using ternary assignment
I have 3 apples
#2.2. print value with ternary assignment
I have 3 apples
I have 3 apples
|