Write a shell program to test whether a given number is even
or odd?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
What is a shell script? Can you name some of its advantages?
How does path variable work?
Explain about sourcing commands?
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.
What is shell geeksforgeeks?
what is this line in the shell script do ?#!/bin/ksh
What is awk in shell scripting?
I want to monitor a continuously updating log file, what command can be used to most efficiently achieve this?
How would you compare the strings in a shell script?
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
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.
What is an sh file?