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



Create a bash shell script that reads in a number from the user. If the number is 1, print out the ..

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

Create a bash shell script that reads in a number from the user. If the number is 1, print out the ..

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

Create a bash shell script that reads in a number from the user. If the number is 1, print out the ..

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

Create a bash shell script that reads in a number from the user. If the number is 1, print out the ..

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

Post New Answer

More Shell Script Interview Questions

What is sed in shell script?

0 Answers  


What are the advantages of shell scripting?

0 Answers  


What is option in shell script?

0 Answers  


Write a command sequence to find all the files modified in less than 2 days and print the record count of each.

0 Answers  


Write a script to print the first 10 elements of fibonacci series.

0 Answers  


write a shell program to check wheather a given string is pallindrome or not?

4 Answers  


How do you read arguments in a shell program - $1, $2 ..?

4 Answers  


How does path variable work?

0 Answers  


What is shell and terminal?

0 Answers  


How will you find the 99th line of a file using only tail and head command?

0 Answers  


How do you rename the files(*.sh) with file names containing space in it?for example "interview question.sh" needs to rename to "interview-question.sh". Appreciate your inputs.Thanks.

5 Answers   Wells Fargo,


What is a file basename?

0 Answers  


Categories