Results 1 to 2 of 2
OK, I've tried doing these, and I am out of time. I will keep trying, but I will post my projects here. Project 1: CREATING A SCRIPT 1) Create a ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 08-13-2011 #1
- Join Date
- Aug 2011
School Help: Scripting and Functions
CREATING A SCRIPT
1) Create a script that asks the user for a file and then appends the date to the file the user has entered. Let the user know if the file can or cannot be written too. Also, if the file does not exist create the file and write the date in the newly created file. Lastly display to the user the file, including a statement letting them know that the file has changed. (Hint remember the –f and –w when evaluating a file in an if statement)
2) Create a script that takes two numbers as input from the user, and then asks the user if they would like to add or subtract the two numbers (use a case statement). Then print out the result in a friendly message. Be sure to let the user know if they choose an option that was not on the menu. You will need to use expr (expression) command when evaluating, as in number=`expr $num1 + $num2` along with the backquotes to store the results in the number variable (also note the s p a c e s).
Now modify your case statement so the user can use either an upper or lower case letter in the menu. That is if the user types a or A both will allow the case statement to run the add selection. (Hint use | as the or operator)
And for Project 2:
You will create a file called .myfunctions that has 2 functions.
1) The first function will be called m and it will allow you to send an email to someone using the mail command. The function should take the To: address, a Cc: address using the –t parameter, a subject line using the –s parameter and an input file. When running this function, you will type something like the following as an example:
m teachernameATschoolDOTedu teachername Lab8 someinputfile.
This will send an email to me with a copy to teachername (which will email my local account on opus) with a subject line of Lab8 and the message will contain the contents of a file called someinputfile. You will need to use the positional parameters as discussed on pages 360-361 of the text to read in the different inputs.
2) The second function will be called e and will calculate some number raised to a power. You can use the following code to create the second function:
while [ "$y" -gt "0" ]; do
echo “The result of $1 raised to the $2 is $z”
To run this function, you will just type e 2 10, for example, and the computer would respond with “The result of 2 raised to the 10 is 1024”.
3) Once you’ve created your .myfunctions file, load it into memory and tell me what command you used to load the file.
4) Use the e function and compute 230, 240 and 250. Send me the results along with the answers to the following questions about status codes.
- 08-13-2011 #2
- Join Date
- May 2004
- arch linux
Hello and welcome!
Sorry, but homework questions are not allowed on the forums: