Skip to content

Instantly share code, notes, and snippets.

@yashppawar
Created June 9, 2022 13:43
Show Gist options
  • Save yashppawar/29180989d2d74b9ced5d3e9defbd63b4 to your computer and use it in GitHub Desktop.
Save yashppawar/29180989d2d74b9ced5d3e9defbd63b4 to your computer and use it in GitHub Desktop.
Linux Basics Micro Project
# Write a shell program to do the following
# 1. Take first name as input from user
# 2. Take second name as input from user
# 3. Display both names individualy
# 4. Display the message "Welcome $first_name and $second_name"
# 5. Redirect this output to a file
(
# Input First Name
echo -n "Enter first person's name: "
read first_name
echo "$first_name" # Print just name
# Input Second Name
echo -n "Enter Second person's name: "
read second_name
echo "$name2" # Print just name
# Display both names together
echo "Welcome $first_name and $second_name"
) | tee logfile.txt # log to a file and output to console
# Write a shell script to Calculate Gross Salary of Employee.
# ( HRA = 20% of basic salary, DA = 50% of basic salary )
# constants
HRA=0.2 # 20% House Rent Allowance
DA=0.5 # 50% Daily Allowance
echo -n "Enter Basic Salary: "
read basic_salary
if [[ ! $basic_salary =~ ^[0-9]+$ ]] ; then
>&2 echo "Please enter a number!"
exit -1
fi
gross_salary=$((
$basic_salary +
$(echo "($basic_salary*$HRA)/1" | bc) +
$(echo "($basic_salary*$DA)/1" | bc)
))
echo "Gross Salary: $gross_salary"
# Write a shell program for the following
# 1. Execute commands to add "Hello GPP" 5 times in a file in vi editor
# 2. Execute a command to sort a file in alphabetical order with numbered list
for i in {1..5}
do
echo "Hello GPP" >> my_file.txt
done
echo -n "do you want to open file in vi? [y/N]: "
read res
if [[ $res == "y" || $res == "Y" || $res == "Yes" || $res == "yes" || $res == "YES" ]]
then
vi my_file.txt
fi
# Display contents of two files in stored format with numbers to each line
if [[ $# -lt 2 ]]
then
echo "Invalid Usage: $0 file1 file2"
exit -1
fi
cat -n $1 $1
# Write a program to find misspelled words from two files and write the output to a new file
if [[ $# -lt 2 ]]
then
echo "Invalid Usage: $0 file1 file2"
exit -1
fi
spell $1 $2 | tee wrong-spellings.txt || echo "Spell Not installed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment