Archived

This topic is now archived and is closed to further replies.

Zach Parise

Unix HELP!

Recommended Posts

hey fellow canucks !

im stuck on an assignment for UNIX command and looking for a solution heres the question.

Write a script in Korn shell to input two positive integer numbers “N” and “M” then perform the following:

  1. If “N” is not smaller than “M” then you need to ask user to enter another set of values for “N” and “M”

  2. If the input value for “N” is smaller than “M” then

    1. Display all the even numbers between the “N” and ‘M”

So basically I have to enter a number say 1 and another number 56

and in between those 2 numbers i must display all the even numbers

any help?

Share this post


Link to post
Share on other sites

Code:


~ # cat test1

#!/bin/ksh

echo enter the first number:

read num1

echo enter the second number:

read num2

for((i=($num1 + ($num1%2)); i < ($num2-3); i+=2)); do printf "%s " $i; done

echo $((i+2))

Test:

~ # ./test1

enter the first number:

1

enter the second number:

13

2 4 6 8 12

Add the logic for checking if the first number is larger. That should be straight forward.

Share this post


Link to post
Share on other sites

Code:


~ # cat test1

#!/bin/ksh

echo enter the first number:

read num1

echo enter the second number:

read num2

for((i=($num1 + ($num1%2)); i < ($num2-3); i+=2)); do printf "%s " $i; done

echo $((i+2))

Test:

~ # ./test1

enter the first number:

1

enter the second number:

13

2 4 6 8 12

Add the logic for checking if the first number is larger. That should be straight forward.

Share this post


Link to post
Share on other sites

A command that runs in UNIX.

That's what I do for a living - I'm an Unix Admin.

Share this post


Link to post
Share on other sites

I'd rather just use Windows. Both have their advantages and disadvantages. I took a Microsoft Server course that also involved Unix/Linux and I'm not a fan of the command operated OS.

Windows is incredibly easy.. Then again that right there is also an issue..

Share this post


Link to post
Share on other sites

  • Recently Browsing   0 members

    No registered users viewing this page.