Results 1 to 4 of 4
I am having trouble completing an assignment for class. I am tasked with asking the user for input, then using the input as the name of the file. I have ...
- 11-18-2008 #1Just Joined!
- Join Date
- Nov 2008
- Posts
- 3
New to Linux scripts
I am having trouble completing an assignment for class. I am tasked with asking the user for input, then using the input as the name of the file. I have been reading and wrestling with this for a week now. I am not asking for anyone to do my homework, but please assist.
Code:echo -n "Please enter a file name: " read filename while [ -z "$filename" ] do echo -n "Please enter your name: " read filename done echo "####################################" > tempFile1 echo "# This name of this file is:" $filename > tempFile2 echo "# Creation date and time:" $(date) > tempFile3 echo "####################################" > tempFile4 cat tempFile1 tempFile2 tempFile3 tempFile4 > sample rm tempFile1 tempFile2 tempFile3 tempFile4 cat filename | rename sample
- 11-18-2008 #2
OK, I really don't like to do someone's homework for them, but you've got pretty far on your own, so I think I'll give you a couple of hints.
First, when you make a variable in a file (as you have with "filename"), you need to refer to it with a dollar sign ($) in front of it in the rest of the script. i.e. "$filename" is correct, but "filename" is wrong.
Secondly, you can do this without creating all those temporary files. You're echoing those strings to four different temp files, but why not echo them to the final file ($filename), in such a way that you concatenate the new string on the end of the file instead of overwriting?
That should be enough to get you going! Good luck
Registered Linux user #388328 || Registered LFS user #15880
AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 9400 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
Need instant help? Try us on IRC -- #linuxforums on freenode
- 11-18-2008 #3
Another piece of the puzzle is to look up what ">>" does in script language.
- 11-19-2008 #4Just Joined!
- Join Date
- Nov 2008
- Posts
- 3
Thanks smolloy & Ajax4Hire. I really did not expect for someone to do my homework, I just needed direction. I did contcatenate my data using >> and it worked great.I took a Java class and did pretty well, so I understand the concept of programming, just needed find the correct syntax. I finally figured it out though. I used "mv currentfilename valueof$filename" to ultimately allow the user to decided what the filename would be. Again, thanks alot.


Reply With Quote