{"id":2257,"date":"2017-12-08T05:56:52","date_gmt":"2017-12-08T05:56:52","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=2257"},"modified":"2020-01-09T09:28:43","modified_gmt":"2020-01-09T09:28:43","slug":"write-script-using-case-statement-to-perform-basic-math-operation-as","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/write-script-using-case-statement-to-perform-basic-math-operation-as\/","title":{"rendered":"Write Script, using case statement to perform basic math operation as"},"content":{"rendered":"<p><strong>rajeshkumar created the topic: Write Script, using case statement to perform basic math operation as<\/strong><\/p>\n<p>Write Script, using case statement to perform basic math operation as<br \/>\nfollows<br \/>\n+ addition<br \/>\n&#8211; subtraction<br \/>\nx multiplication<br \/>\n\/ division<br \/>\nThe name of script must be &#8216;q4&#8217; which works as follows<br \/>\n$ .\/q4 20 \/ 3, Also check for sufficient command line arguments<\/p>\n<p><code>#!\/bin\/bash<br \/>\n#<br \/>\n# Linux Shell Scripting Tutorial 1.05r3, Summer-2002<br \/>\n#<br \/>\n# Written by Vivek G. Gite <vivek@nixcraft.com><br \/>\n#<br \/>\n# Latest version can be found at http:\/\/www.nixcraft.com\/<br \/>\n#<br \/>\n# Q4<br \/>\n#<\/p>\n<p>if test $# = 3<br \/>\nthen<br \/>\n\tcase $2 in<br \/>\n\t +) let z=$1+$3;;<br \/>\n\t -) let z=$1-$3;;<br \/>\n\t \/) let z=$1\/$3;;<br \/>\n\t x|X) let z=$1*$3;;<br \/>\n\t *) echo Warning - $2 invalied operator, only +,-,x,\/ operator allowed<br \/>\n\t    exit;;<br \/>\n\tesac<br \/>\n\techo Answer is $z<br \/>\nelse<br \/>\n\techo \"Usage - $0   value1  operator value2\"<br \/>\n\techo \"        Where, value1 and value2 are numeric values\"<br \/>\n\techo \"               operator can be +,-,\/,x (For Multiplication)\"<br \/>\nfi<\/p>\n<p>#<br \/>\n# .\/ch.sh: vivek-tech.com to nixcraft.com referance converted using this tool<br \/>\n# See the tool at http:\/\/www.nixcraft.com\/uniqlinuxfeatures\/tools\/<br \/>\n#<\/code><\/p>\n<p>Regards,<br \/>\nRajesh Kumar<br \/>\nTwitt me @ <a href=\"http:\/\/twitter.com\/RajeshKumarIn\" target=\"_blank\" rel=\"noopener\">twitter.com\/RajeshKumarIn<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>rajeshkumar created the topic: Write Script, using case statement to perform basic math operation as Write Script, using case statement to perform basic math operation as follows + addition &#8211;&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[454],"tags":[278],"class_list":["post-2257","post","type-post","status-publish","format-standard","hentry","category-shell-script","tag-script"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=2257"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2257\/revisions"}],"predecessor-version":[{"id":2258,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2257\/revisions\/2258"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=2257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=2257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=2257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}