logo


Home Linux Howtos (Exercises) Linux shell script exercise
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
will give you what is your input,

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
/etc/postfix
Directory contents are as below :

access             generic        main.cf          master.cf       post-install  transport
bounce.cf.default  header_checks  main.cf.default  postfix-files   relocated     virtual
canonical          LICENSE        makedefs.out     postfix-script  TLS_LICENSE
[root@station100 script]#

[root@station100 script]# sh if4.sh /etc/test
/etc/test
There is no directory :
[root@station100 script]#

 

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/script
[root@station100 script]#

[root@station100 script]# ls
file2.txt  if1.sh  if3.sh  if5.sh     testfile2  testfile4  test.sh
file.txt   if2.sh  if4.sh  testfile1  testfile3  testfile5
[root@station100 script]#

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"
Listin only *.txt files from /root/script directory

/root/script/file2.txt  /root/script/file.txt

For example if my script name is if5.sh, my directory name is "/root/script" and want to list "*.sh" then


[root@station100 script]# sh if5.sh /root/script "*.sh"
Listin only *.sh files from /root/script directory

/root/script/if1.sh  /root/script/if3.sh  /root/script/if5.sh
/root/script/if2.sh  /root/script/if4.sh  /root/script/test.sh

[root@station100 script]#

 

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
Please give any string is input :
Hey! You forgot to give input

With input

[root@station100 script]# sh if5.sh
Please give any string is input :test
The input is test
[root@station100 script]#


 

 

Exam Schedule

RHCE Exam For Feb-2011

RHCE Exam :- 24-02-2011

RH423 Exam :- 25-02-2011

RHCVA Exam :- 25-02-2011



Latest Update





Do the Register for RHCE Exam and get a fantastic scheme from Red Hat.

RHCE Full Time Batch is already started and RHCSS (RH423) Batch will start soon.

Last RHCE exam result at Electromech: November 27
Name RESULT
Mr. Jigar RHCE
Mr. Sujit RHCE
Mr. Prtyay RHCE
Mr. Pritesh RHCE
Mr. Hardik RHCE
Mr. Gaurav RHCE
Mr. Milan RHCE
Mr. Sachin RHCE
Ms. Shrusti RHCE
Mr. Paras RHCE
Mr. Dhruvin RHCE
Mr. Sneh RHCE
Mr. Jigar RHCE
Mr. Nishant RHCE
Mr. Dinesh RHCE
Mr. Manthan RHCE
Mr. Vinay RHCE
Mr. Pradip RHCE
Mr. Kausal RHCE
Mr. Gopan RHCT
Mr. Jagdish RHCT



Powered by Electromech Corporation.