The below code snippet shows how do the arithmatic expression in shell script.
-bash-3.2$ cat arithmatic_sh
#!/bin/bash
let "z=5**3" # 5 * 5 * 5
echo "z = $z" # z = 125
expr 5 % 3 #2
n=1; echo -n "$n "
let "n = $n + 1" # let "n = n + 1" also works.
echo -n "$n "
(( n = n + 1 ))
# A simpler alternative to the method above.
echo -n "$n "
n=$(($n + 1))
echo -n "$n "
(( n++ )) # (( ++n )) also works.
echo -n "$n "
echo
exit 0
Output :
-bash-3.2$ sh arithmatic_sh
z = 125
2
1 2 3 4 5
-bash-3.2$
let "z=5**3" --> 5*5*5 assigned into variable z (5 will be multiply by 3 times)
some thing special in mulitplication
-bash-3.2$ cat simple_multiplication
echo Enter the multiplication number required:
read number
for i in 1 2 3 4 5 6 7 8 9 10
do
echo "$number * $i =`expr $number \* $i`" # slash star is important bz it differenciate from regular exp
done
OUTPUT :
-bash-3.2$ sh simple_multiplication
Enter the multiplication number required:
2
2 * 1 =2
2 * 2 =4
2 * 3 =6
2 * 4 =8
2 * 5 =10
2 * 6 =12
2 * 7 =14
2 * 8 =16
2 * 9 =18
2 * 10 =20
-bash-3.2$
A Language is not worth knowing unless it teaches you to think differently.
Subscribe to:
Post Comments (Atom)
Price List Query for Item
SELECT qph.list_header_id, qph.name, qph.description, qphh.start_date_active, qphh.currency_code, q...
-
1. To download Ldt file for a Concurent Program FNDLOAD [username]/[password] O Y DOWNLOAD $FND_TOP/patch/115/import/afcpprog.lct file_nam...
-
Here the article will describe about how to register WebADI to Responsibility menu Go to System Administrator --> Security --> Respo...
-
using the below query can check the invoice status. SELECT DECODE(AP_INVOICES_UTILITY_PKG.GET_APPROVAL_STATUS(AIA.INVOICE_...
No comments:
Post a Comment