Unix Assignment Write a script named ifthen that prompts the user with >> and re
ID: 3599152 • Letter: U
Question
Unix Assignment
Write a script named ifthen that prompts the user with >> and reads a string of text from the user. If the user enters a nonnull string, the script displays You entered: followed by the string; otherwise it displays Where is your input?. Use an if...then...else control structure to implement the two-way branch in the script. Use a test to determine if the user enters a null string. What do you have to do to avoid getting an error message when you prompt with >>?
Deliverables:
1. Submit your results for both null and nonnull test cases in your homework doc.
2. Submit your answer to the question regarding >> in your homework doc also.
Explanation / Answer
Implemented unix shell scriptt as per the requirement. Please comment if you have any doubt or any modification required.
What do you have to do to avoid getting an error message when you prompt with >>?
Ans: Just include the message in double quotes (" "). Then terminal will throw any error.
#Prompt message
echo "Enter a string >> "
read varname #reading input
if [ -z "$varname" ]; then #Checking for null values
echo Where is your input? #Prompt for null values
else
echo You entered $varname #Result for nonnull values
fi
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.