By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,822 Members | 1,038 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,822 IT Pros & Developers. It's quick & easy.

hi guys

P: 1
i have problem with this exercise:

Usually, shell scripts are not well-equipped to do arithmetics but rely on the output from other
programmes. But simple operations with integers can be performed using the shell command expr.
Write a script that takes in an integer as input and
1. if the integer is greater than 3, multiply it by two,
2. if it is smaller than 3, multiply it by three.
3. if it is equal to 3, display an error message.

So the execution should look like
hande@p439a:~$ sh 4
result = 8
hande@p439a:~$ sh 3
You’ve entered 3. Enter a different number.
hande@p439a:~$ sh 1
result = 3

1. You can use the if construct.
2. Read the lecture notes for examples of the usage of expr.

can you show me how to do it please
Oct 18 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 2.5K+
P: 3,237
Hi luayRabie,

Please read the Posting Guidelines, in particular, the rules about posting homework related questions.

Thank you, and welcome to The Scripts.
Oct 18 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.