Difference between revisions of "Chapter 5 answers"

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to navigation Jump to search
Line 6: Line 6:
 
# False
 
# False
 
# False
 
# False
# To executes for each value in a list use while loop.
 
 
# False
 
# False
 +
# False
 +
# True
 
# True
 
# True
# The PS3 reserved variable is used by select statement.
+
# True
# 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 menu driven script using the select statement to print calories for food items such as pizza, burger, Salad, Pasta etc.
 +
<source lang="bash"></source>
 +
 +
----
 +
 
* 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 vowels, blank spaces, characters, number of line and symbols.
 +
<source lang="bash"></source>
 +
 +
----
 +
 
* 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 count English language articles such As 'A', 'An' and 'The'.
 +
<source lang="bash"></source>
 +
 +
----
 +
 
* 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 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.
 +
<source lang="bash"></source>
 +
 +
----
 +
 
* 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 monitor Linux server disk space using a while loop. Send an email alert when percentage of used disk space is >= 90%.
 +
<source lang="bash"></source>
 +
 +
----
 +
 
* 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 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.
 +
<source lang="bash"></source>
 +
 +
----
 +
 
* 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 *such as 123) and find the sum of digits (1+2+3=6).
 +
<source lang="bash"></source>
 +
 +
----
 +
 
* Write a shell program to read a number and display reverse the number. For example, 123 should be printed as as 321.
 
* Write a shell program to read a number and display reverse the number. For example, 123 should be printed as as 321.
 +
<source lang="bash"></source>
 +
 +
----
 +
 
* Write the shell program which produces a report from the output of ls -l in the following format using the for loop statement:
 
* 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
 
<pre>file1
Line 27: Line 62:
 
Total symbolic links : 0
 
Total symbolic links : 0
 
Total size of regular files : 2940</pre>
 
Total size of regular files : 2940</pre>
 +
<source lang="bash"></source>
 +
 +
----
 +
 
* 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 will count the number of files in each of your sub-directories using the for loop.
 +
<source lang="bash"></source>
 +
 +
----
 +
 
* 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 that accepts two directory names as arguments and deletes those files in the first directory which are similarly named in the second directory.
 +
<source lang="bash"></source>
 +
 +
----
 +
 
* Write a shell script to search for no password entries in /etc/passwd  and lock all accounts.
 
* Write a shell script to search for no password entries in /etc/passwd  and lock all accounts.
 +
<source lang="bash"></source>
 +
 +
----
 +
 
* Write a shell program to read two numbers and display all the odd numbers between those two numbers.
 
* Write a shell program to read two numbers and display all the odd numbers between those two numbers.
 +
<source lang="bash"></source>
 +
 +
----
  
 
[[Category:Control flow loop]][[Category:Commands]]
 
[[Category:Control flow loop]][[Category:Commands]]

Revision as of 16:48, 25 December 2009

← Chapter 5 ChallengesHomeChapter 6: Shell Redirection →

  • Decide whether the following sentence is true or false:
  1. False
  2. False
  3. False
  4. False
  5. True
  6. True
  7. True

  • 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 →