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

What is a shell script? Can you name some of its advantages?

0 Answers  


How does path variable work?

0 Answers  


Explain about sourcing commands?

0 Answers  


A file has multiple records each having three 30-bit long fields(field1,field2,field3).There is also a lookup file,LOOK_UP.dat.Now, we need to consider only the last ten digits of field1 and lookup the file LOOK_UP.dat. If there a match then field2 and field3 should replaced with corresponding data from the lookup file. otherwise that particular record,for which there is no match, should be stored in a seperate file.

2 Answers   Wipro,


What is shell geeksforgeeks?

0 Answers  


what is this line in the shell script do ?#!/bin/ksh

5 Answers  


What is awk in shell scripting?

0 Answers  


I want to monitor a continuously updating log file, what command can be used to most efficiently achieve this?

0 Answers  


How would you compare the strings in a shell script?

0 Answers  


RAM one table colums a1,a2,a3,a4 respective values 2,4,7,8 KRISH one table colums a1,a2,a3,a4 respective values 3,4,6,9 IN RAM & KRISH a4 column if comparing values RAM A4 - KRISH A4 ( 8-9 =1 THEN print 5 or (RAM) a4 value 10 KRISH a4 values 2 then 10 -2 =8 print 5*8=40 or diff 5 print same

1 Answers   Tech Mahindra,


How to sort a result of Ls -l command based on columns. Ex. i want to sort 5th column from output of ls -l command.

6 Answers   TCS,


What is an sh file?

0 Answers  


Categories