RedHat Products
| Linux shell script exercise |
Linux shell script exercise
Shell script No. 1 Write a shell script which will ask for input as directory with path i.e. /etc/pam.d, 1 if directory with path exist then will print directory exist 2. if input (/etc/pamdd) is wrong or not a directory then will print "The directory /etc/pamdd not exist or it is not directory" Hint : man test, or test --help
Shell script No. 2 write a shell script which will ask for input as directory or file with path ie /root/install.log 1 if directory / file with path exist then will print directory or file exist 2. if input (/etc/pamdd) is wrong or not a directory / file then will print "The directory or file /etc/pamdd not exist" Hint : man test, or test --help
Shell script No. 3 Write a shell script, which will ask you for input 'yes' or 'no' and based on that 1. If you enter yes as your input it will echo you have entered yes. 2. If you enter no as your input it will echo you have entered no. 3. No or Invalid input is given than gives error 'no input given'.
Shell script No. 4 Write a shell script, you need to give input at command line it self. like the shell script will be executed as sh scriptname.sh /etc/postfix So input will be given at command line only, here /etc/postfix is input 1. If directory exist then will list the content of the directory 2. If directory not exist then will print "No directory exist." Hint: Positional parameters $0, $1,$2,$3..$9, $*,$#, $@ Sample executed shell script [root@station100 script]# sh if4.sh /etc/postfix [root@station100 script]# sh if4.sh /etc/test
Shell script No. 5 Please create directory script and some files in that with extension ".sh" and ".txt" or any other extension. Example as below directory. [root@station100 script]# pwd [root@station100 script]# ls Create a shell script which will take input from positional parameters. The first argument will the directory and the second argument is file extension type. For example if my script name is if5.sh, my directory name is "/root/script" and want to list "*.txt" then [root@station100 script]# sh if5.sh /root/script "*.txt" For example if my script name is if5.sh, my directory name is "/root/script" and want to list "*.sh" then
Shell script No. 6 Write a shell script which can identify if there is no input given when asked. The sample execution is as below. No input [root@station100 script]# sh if5.sh With input [root@station100 script]# sh if5.sh
|
Exam Schedule
Latest Update
Powered by Electromech Corporation.