Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a bash script that: Prompts a user to enter his/her user\'s first and last

ID: 3828537 • Letter: W

Question



Write a bash script that: Prompts a user to enter his/her user's first and last names, reads user inputs into 2 variables, checks if both of the variables are not empty (check if the user entered at least 2 strings), prints user's last and first names (note reversed order), and exit with failure (value 1) and appropriate message if the user did not enter two strings. Your script should be named according to the following convention where Your Name should be replaced by the first letter of your first name combined with your last name

Explanation / Answer

steps to execute

1.save the script to filename.sh

2. run using ./filename.sh

3. when you run it it may give permission denied error use chmod 777 filename.sh

#!/bin/bash

echo -n "Enter first name:"
read fname
echo -n "Enter last name:"
read lname
length1=${#fname}
length2=${#lname}
if [ $length1 -gt 0 ] && [ $length2 -gt 0 ]
then
echo "You entered: $lname $fname"
else
echo "Please enter both strings"
exit 1
fi

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote