Chapter 5 Challenges

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to: navigation, search
← Command substitutionHomeChapter 6: Shell Redirection →
  • Decide whether the following sentence is true or false:
  1. For repeated actions use if-then-else.
  2. For choice making use bash shell loop.
  3. To executes for each value in a list use while loop.
  4. Use break statement to return to the top of the loop.
  5. Use continue statement to return to the top of the loop.
  6. The PS3 reserved variable is used by select statement.
  7. The default value for PS3 is set to #?.
  • Write a menu driven script using the select statement to print calories for food items such as pizza, burger, Salad, Pasta etc.
  • Write a shell script that, given a file name as the argument will count vowels, blank spaces, characters, number of line and symbols.
  • Write a shell script that, given a file name as the argument will count English language articles such As 'A', 'An' and 'The'.
  • Write a shell script that, given a file name as the argument will write the even numbered line to a file with name evenfile and odd numbered lines in a text file called oddfile.
  • Write a shell script to monitor Linux server disk space using a while loop. Send an email alert when percentage of used disk space is >= 90%.
  • Write a shell script to determine if an input number is a palindrome or not. A palindromic number is a number where the digits, with decimal representation usually assumed, are the same read backwards, for example, 58285.
  • Write a shell program to read a number *such as 123) and find the sum of digits (1+2+3=6).
  • Write a shell program to read a number and display reverse the number. For example, 123 should be printed as as 321.
  • Write the shell program which produces a report from the output of ls -l in the following format using the for loop statement:
file1
file2
[DIR] test/
Total regular files : 7
Total directories : 4
Total symbolic links : 0
Total size of regular files : 2940
  • Write a shell script that will count the number of files in each of your sub-directories using the for loop.
  • Write a shell script that accepts two directory names as arguments and deletes those files in the first directory which are similarly named in the second directory.
  • Write a shell script to search for no password entries in /etc/passwd and lock all accounts.
  • Write a shell program to read two numbers and display all the odd numbers between those two numbers.
← Command substitutionHomeChapter 6: Shell Redirection →