Click to See Complete Forum and Search --> : Linux/School question


Beavis
11-07-2001, 05:08 PM
We are learning linux in our computer science class at school. Our latest lab question to complete is : Create a script that will exchange two files. That is, if I currently have two files One and Two, after executing the script, One will contain the data of Two and visa versa.

If anyone could help me out with this I'd really appreciate it. We are using mandrake 8.0 with no gui. Thanks in advance! :confused:

error27
11-07-2001, 05:47 PM
Life is tons and tons happier with a GUI.

Even terminal windows are better in a GUI.

mv one was_one
mv two one
mv was_one two

(normally i don't do other people's homework for them but since you have no gui I have pity for you.)

AdaHacker
11-07-2001, 06:07 PM
Normally, I would frown on doing other people's homework and give you the wrong answer on purpose, but I also have pitty on you for lacking a GUI. Plus error27 beat me to the punch. ;)
What I want to know is, why use Mandrake without a GUI? That's like running Windows 98 so you can have a DOS prompt. If it were Slackware or FreeBSD, I would understand, but Mandrake?

slacker_x
11-07-2001, 09:07 PM
cat file1 > temp_file1
cat file2 > temp_file2
cat temp_file2 > file1
cat temp_file1 > file2
rm -f temp_file1 temp_file2


I'm not saying that's pretty, but it's the easiest way I could think of doing it. Make sure you understand what's going on here before you submit the assignment.
I guess the concept that the teacher was trying to demonstrate is redirecting stdout. That's what the ">" does. Instead of printing the contents of the file on your screen (which is what cat file1) would do, it prints the contents of the original file into the other file.

camelrider
11-07-2001, 09:16 PM
Your grade might be better if you add comments in order to demonstrate that you DO know what is going on, regardless of which solution you choose.
edit:
Hint-
man mv
man cat
man rm
and read a bit about redirection.
;)

[ 07 November 2001: Message edited by: camelrider ]

evil_roy
11-07-2001, 09:37 PM
Definately add comments - overdo the comments even.

Without comments you should get a 0 . Even if the script works.

When learning - the comments can be more important than the code itself. It shows that you understand what is going on and that you understand the concepts.

It is also an invaluable habit to acquire that will benefit yourself and others.

Beavis
11-08-2001, 02:45 AM
Thanks for all the replies! I have no idea why our class is not using a gui. Our professor, for whatever reason, set it up that way. So we sprend our class watching him work on that boring black screen, while we follow along on our boring black screens. However, I bought mandrake 8.1 to learn at home and I AM using a gui! :D

bdg1983
11-08-2001, 06:30 AM
You will never learn to use Linux properly unless you use the commandline. I use the gui, but I always have a terminal open at all times and use that more than anything else.