http://www.linuxplanet.com/linuxplanet/tutorials/6699/1
Intro to Shell Programming: Writing a Simple Web GalleryA Simple ScriptMarch 12, 2009 So you're not a programmer, you say? If you can string a few shell commands together, it's not much of a step from there to programming. To demonstrate that, I'll take you through the steps of writing a very simple web gallery script: one that will take your images and build a little web page to show them off. Your script will need to do some image operations like resizing from the command-line. For that, I recommend ImageMagick, available as a package in just about every Linux distro. Just For this project, you'll also want a directory with some images in it. You can create a directory with In a shell, change directory (cd) into your new image directory; you'll be running your script from there. Create your shell scriptTo create your shell script, use a text editor, not a word processor like OpenOffice. If you don't have a favorite text editor yet, check out the recent LinuxPlanet articles on Kate. A shell script is, at its most basic, a list of commands you want the shell to run. It starts with a magic line: #! /bin/sh That's called a shebang line, because the # character is usually pronounced "hash" and the !, "bang". It lets you run your script like a program, by just typing the program name, and Linux will figure out that it's a shell script, run by the shell, /bin/sh. There's one other step you need before you can run your shell script: you need to make it executable. Choose a file name (say, gal for gallery) and save your shell script. Then, in a shell, you can change its permissions this way: chmod ugo+x gal (that means "Make the file executable for user, group and other.") If you prefer using gui tools, right-click on your newly created script, choose Properties and look for the Permissions tab: you can make the script executable there. Now you have a shell script, and it's runnable. But it doesn't do anything. That's the next step. |