Tuesday, November 22, 2005

Learning by Playing Around, and a Psychological Time Bomb

I learn the shell by playing around.

Using the up-arrow key to recall commands, plus the backspace and left-and right-arrow keys to edit them, you can do a lot of quick, little experiments.

Try it now.

Start as usual:
./hello > 1
cat 1
What happens if the ">" symbol is in front of the command instead of after it?
> 2 ./hello
cat 2
What happens if there's no command at all?
> 3
cat 3
What happens if there's already something in the file you're writing to?
echo Your mother wears army boots. > 4
./hello > 4
cat 4
What happens if you accidentally write to yourself?
./hello > hello
cat hello
This last experiment shows you that the shell starts redirection before it runs the command. The shell opens up the output file, hello, cleans it out in preparation for filling it with the output of the the command "./hello," and then, uh, ... finds it's painted itself into a corner. The command you've told it to run is now an empty file.

You will do this to yourself eventually. Instead of being mystified, you'll remember this, smack your forehead, and say, "Dang!"

I'm setting a psychological time-bomb.

0 Comments:

Post a Comment

<< Home