Write a shell program to test whether a given number is even
or odd?

Answers were Sorted based on User's Feedback



Write a shell program to test whether a given number is even or odd?..

Answer / fariha

echo -n "Enter numnber : "
read n

rem=$(( $n % 2 ))

if [ $rem -eq 0 ]
then
echo "$n is even number"
else
echo "$n is odd number"
fi

Is This Answer Correct ?    240 Yes 73 No

Write a shell program to test whether a given number is even or odd?..

Answer / mani

echo "Enter the Number"
read a
b=`echo "$a % 2"|bc`
if [ $b -eq 0 ]
then
echo "Given Number is Even "
exit
fi
echo " Given Number is odd"

Is This Answer Correct ?    67 Yes 34 No

Write a shell program to test whether a given number is even or odd?..

Answer / kushal

echo 10|awk '{ if($0 % 2 == 0) print "Even Number"; else
print"Odd Number"}'

tested and certified one liner answer

Is This Answer Correct ?    28 Yes 17 No

Write a shell program to test whether a given number is even or odd?..

Answer / rk

echo"enter number"
read n
set r=($n%2)
if(r eq-0)
then
echo "even number:$n"
else
echo "odd number:$n"
fi

Is This Answer Correct ?    24 Yes 16 No

Write a shell program to test whether a given number is even or odd?..

Answer / santana20142003

$ echo <number> | nawk '{ if($0 % 2 ==0) print $0 "Even
Number" ;\
else print $0 "Odd Number"}'

Is This Answer Correct ?    24 Yes 17 No

Write a shell program to test whether a given number is even or odd?..

Answer / 111

1111

Is This Answer Correct ?    8 Yes 7 No

Write a shell program to test whether a given number is even or odd?..

Answer / karishma

echo -n "Enter numnber : "
set number = $<

set rem=expr( $number % 2 )

if($rem -eq 0)
then
echo "$number is even number"
else
echo "$number is odd number"
endif

Is This Answer Correct ?    19 Yes 19 No

Write a shell program to test whether a given number is even or odd?..

Answer / padmas

echo -n "Please give any odd number : "
read n

rem=$(( $n % 2 ))

if [ $rem -eq 0 ]
then
echo "Thank you for giving even number."
else
echo "Yes, it is odd"
fi

Is This Answer Correct ?    9 Yes 12 No

Post New Answer

More Shell Script Interview Questions

write a scwipt that a) takes exactly one argument, a directory name. b) if the number of argument is more or less than one,print a usage message c) if the argument is not adirectory, print another message d) for the given directory, print the five biggest files and the five files that were most recently modified. e) save the output to a file called q2output.

2 Answers  


Hi, all Scripting professional. Q. I have written script1.sh and calling script2.sh in script1.sh file using bash shell as interpreter and my log in shell also bash shell.My code like Script1 #!/bin/bash echo "My script2 call" . script2.sh Here script2.sh file run successfully but when I have changed my interpreter bash to ksh like #!/bin/ksh Error are comming script2.sh command not found. Guid me how to call other script in our main script.

2 Answers  


How to print some text on to the screen?

2 Answers  


What is shift command in shell script?

0 Answers  


What is the equivalent of a file shortcut that we have a window on a linux system?

0 Answers  






What is a shell script in windows?

0 Answers  


What lives in a shell?

0 Answers  


What is meant by $1 in shell script?

0 Answers  


is there any command to find user password?

4 Answers  


how will you find the total disk space used by a specific user?

0 Answers  


What is the first line in every perl script called?

0 Answers  


What are types of shells?

0 Answers  


Categories