Difference between revisions of "Chapter 5 answers"

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to navigation Jump to search
Line 3: Line 3:
 
|next=Chapter 6: Shell Redirection}}
 
|next=Chapter 6: Shell Redirection}}
  
 +
* Decide whether the following sentence is true or false:
 +
# False
 +
# False
 +
# To executes for each value in a list use while loop.
 +
# False
 +
# True
 +
# The PS3 reserved variable is used by select statement.
 +
# 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:
 +
<pre>file1
 +
file2
 +
[DIR] test/
 +
Total regular files : 7
 +
Total directories : 4
 +
Total symbolic links : 0
 +
Total size of regular files : 2940</pre>
 +
* 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.
  
 
[[Category:Control flow loop]][[Category:Commands]]
 
[[Category:Control flow loop]][[Category:Commands]]

Revision as of 16:44, 25 December 2009

← Chapter 5 ChallengesHomeChapter 6: Shell Redirection →

  • Decide whether the following sentence is true or false:
  1. False
  2. False
  3. To executes for each value in a list use while loop.
  4. False
  5. True
  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.

← Chapter 5 ChallengesHomeChapter 6: Shell Redirection →