Create a bash shell script that reads in a number from the
user. If the number is 1, print out the date. If the number
is 2, list the files in the current directory. If the number
is 3, print out who is currently logged onto the system. If
the number is anything else, print out an error message and
exit. Name this script "various.sh"
Answers were Sorted based on User's Feedback
Answer / aryan
cho "Enter Choice"
read num
case $num in
1) echo `date`
;;
2) ls
;;
3) who
;;
*) echo "Wrong option press 1 2 3 only"
;;
esac
Is This Answer Correct ? | 8 Yes | 0 No |
Answer / kasu
echo "Enter the number"
read i
if [ $i -eq 1 ];then
echo `date`
elif [ $i -eq 2 ];then
ls
elif [ $i -eq 3 ];then
who
else
echo "Nothing"
fi
Is This Answer Correct ? | 4 Yes | 1 No |
Answer / avlsubbarao
#!/bin/bash
echo "Enter Number"
read N
if [ $N == 1 ]; then
date
elif [ $N == 2 ]; then
ls
elif [ $N == 3 ]; then
who
else
echo WRONG NUMBER
fi
Is This Answer Correct ? | 2 Yes | 2 No |
Answer / prasad
#!/bin/sh
select num in 1 2 3 any; do
case $num in
1) date;;
2) ls;;
3) who;;
*) echo "Error"; break;;
esac
done
Is This Answer Correct ? | 0 Yes | 0 No |
How to get the 3rd element/column from each line from a file?
How to change our default shell?
What is the difference between a shell variable that is exported and the one that is not exported?
What are script files?
What is eval in shell script?
Why is a script important?
What is the conditional statement in shell scripting?
What is a scripting language simple definition?
What can scripts do?
Is bash a shell script?
How to pass an argument to a script?
What are the different kinds of loops available in shell script?