Interview Questions

Scripting

Shell Script - How to Read File in Shell script ?

This section describes about reading a file line by line using Shell Script.

The below script is a simple one and seems more self explanatory.

ReadProperty.sh

# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR

Shell Script - Find list of Files having Write Permission in a directory

In this section, Let us see how to find the Files which are having Write permission enabled in a particular directory.

In the below script, we are going to find the list of all files inside "/cygdrive/c/Shell_Script" which are having Write permission for the user Owner.

The below script will produce a report.csv file which will have writable files list.

FindFilesHavingWritePermission.sh

# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED

Shell Script - Process Tasks based on User Input

In this section, let us see how to get User Input and execute different tasks based on the User Input data.

In the below article, let us see the following,
1. How to get Input from User
2. How to process the Input i e., a simulation is created so that you can use the below piece of code where ever applicable.

1. User Input:
The list of options available in our application is displayed as options so that User can select the appropriate one.

Shell Script - How to read Property File using Shell Script

In this Shell Script section, Let us see how to fetch the Value from the Property File based on the Key.

Consider a Property File named "Test.prop" which is of the below format,

Test.prop

Name=Admin
Age=24
Occupation=Farmer

In the above Property file, Let us fetch the Value for the key (i.e., Name) and display the same. Go through the below script file once so that we can discuss the steps involved.

ReadProperty.sh

# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''