Exercise
Here are some Shell Scripting tasks for you to practice from the beginning to the advance level.
Lets start with the exercise:
Exercise 1. Write a shell script which prints "I will learn Shell Scripting!" on the terminal. Answer
Exercise 2. Simply change or modify Exercise 1 to include a variable. The variable should hold the value "I will learn Shell Scripting!" and the value or string should be displayed with that variable. Answer
Exercise 3. Store the output of 'whoami' command in a variable and display the out put as "You are logged in as ___" in which "___" will be your username which you logged on. Answer
Exercise 4. Write a shell script to store "I will learn Shill Scripting" in a variable and display on screen with each word on a separate line. You can do it with various ways but try to use minimum number of lines. Answer
Exercise 5. Write a shell script that displays a number of files/directories in your present working directory. Answer
Exercise 6. Write a shell script to check that the 'file_path' is exist or not. If file exist check that file is having read permission or not and then display the content of file if file having read permission, If not then display the message "File is read protected". And if file does not exist then display the message "File is not present". Answer
Exercise 7. Write a shell script that asks the user to enter a file_name and then displays that the file is regular file or directory or other type of file. Answer
Exercise 8. Just modify the previous script, but rather than asking file_name to the user, user should pass the file name as runtime argument. And the number of arguments can be unlimited (not fixed). Answer
Exercise 9. Change previous exercise that if user has not pass the arguments at runtime the message will be display that "please pass the argument at script runtime." Answer
Exercise 10. Write a shell script that asks user to enter an character and then displays that the enter is either form small 'a-z' or capital 'A-Z' or a number '0-9' or any special character like $,?,etc. and if user enter any other value then display message accordingly. Answer
No comments:
Post a Comment