I am working on finishing some Intro. Unix/Linux shell scripting and am confused
ID: 3556736 • Letter: I
Question
I am working on finishing some Intro. Unix/Linux shell scripting and am confused because i have no experience, could you complete this program.
part 1:
Create a shell script called sgen that asks you for your
name and then generates the following file called sgen.out:
##########################################################
#This is a new genout file.
#It was created by: <your name ends up here>
#Creation data and time: Mon Sep 28 19:42:34 EDT 1996
##########################################################
part 2:
Modify sgen to do the following:
a. asks you to type an output file name, for example,
myscript
b. asks you for your name, for example, Ophelia
Glutenschnabel
c. generates an output file with the name you typed that
includes the following:
##########################################################
#script: myscript
#creator: Ophelia Glutenschnabel
#Created: Mon Sep 28 19:42:34 EDT 1996
##########################################################
echo I am the script $0
d. when executed, this new script file responds --
I am the script myscript
* * e. if you don't give the sgen program an output file name
it should display the message "No script name" and
stop, not generating the file. Likewise if you don't
give it a value for your name, it should display "No
name given" and stop. The sgen program should only
generate its output file if both a file name and your
name have been given.
Explanation / Answer
Here's how I would handle step e of the assignment...
echo "Please type a file name for the output file:"
read filename
if [ -z "$filename" ]
then
echo "No script name."
exit
fi
echo -n "Please type your name:"
read name
echo "#####################################################" > $filename
echo "#Filename: $filename" >> $filename
echo "#Creator: $name" >> $filename
echo "#Creation data and time: `date`" >> $filename
echo "#####################################################" >> $filename
echo "I am the sript '$filename'"
The if statement checks for a null value within the variable filename.
The exit command prevents any further execution of the script.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.