Monday, August 19, 2013

Lesson 6 - Scripting

Today we wrote our first script. This kinda patched together all the tricks we've done so far:

- Open a new file in vim. Walking in her father's tracks, she chose to name it after one of her favorite foods, "nakki" (wiener). She struggled with typing vim again, and had a hard time concentrating on the task. Maybe a bit too close to bedtime this lesson?
- Append a new line
- Write a familiar command. We decided we should use the say program again, so she wrote "say pitkätossu".
- Save and exit (she totally mastered this again)
- Run the script: "./nakki". She remembered that she has to use the shift key to enter the slash character, the keyboard position of which we had to find together.


She was quite excited to see what happens.

    ./nakki: Permission denied

That happened. I had forgotten file permissions! I offered to fix the permissions quickly but she refused the offer and insisted on doing it herself to learn it. So we spent some time typing and discussing "chmod u+x nakki". I taught her that she can use the tab key to auto-complete file names.

Back to running the script. She used the tab key to auto-complete the file name.

And the script worked. She learned that you can add any commands into a file and run the file as a script! A script is a file and it's a program too. Whoa!

Now she demanded that I teach her how to write children's games immediately and promised to listen hard. I promised she'll be able to do that when she's five, if we keep on with these sessions for a year.

The last line in the screen shot was typed by the non-vim-user kid.


5 comments:

  1. Totally made me laugh out loud! Wife was wondering what on earth I am doing. :D

    ReplyDelete
  2. Awesome blog, Juha! :D "Dad, I want to talk about vim", instant classic.

    ReplyDelete
  3. Thanks guys!

    The really awesome thing though is how a 4-year old enjoys hacking the command-line. Not sure what will happen in the long run but the fun we've had so far is definitely worth the relatively small investment of like 15 minutes a day. You should try this yourself! I don't mean that everyone should do command-line madness, but something you enjoy yourself and that you can teach your kid and have fun together with.

    ReplyDelete
  4. Hahaha "This is my daughter who uses Vim! ..... "Oh yeah, and this is the other one"

    ReplyDelete