ACPI administration advocacy advocacy advocacy opinion alsa amarok apache apple apt aptitude audio audo authentication automount avi awk bash BIOS boot business cache calendar calibre cdr cdrecord censorship commandline computerscience console convert cron cut database date debian degree design desktop development disk dpkg dvd economics education emacs email europe exim faad ffmpeg file files firefox firewall flash foss freedom ftp fun fuse git gnumeric graphics grep growisofs grub gtkpod hardware hardware html idiocy image imagemagick images installation ip iphone ipod iptables iso itunes ivman kde kernel keyboard knoppix lame laptop latex linux locale lockin longlines m4a microsoft mimetypes minitab mount mp3 mp4 mplayer multimedia music mysql network nfs nfs4 nmap openbox openoffice opinion opinion partition pdf perl php politics postgresql printing privacy programming rant remote rhythmbox rss rsync rxvt scp screengrab screenshot script scripting scsi security sed server shell siteadmin sitenews sitesoftware skype skype slackware sound sox spam spreadsheet ssh statistics subversion sudo svk swap t23 t43 terminal text thinkpad thunderbird time timezone ubuntu udev upgrade usb usbmount users uuid versioncontrol vfat video vnc windows wine wordpress wordprocessing X40 xwindows xwindows youtube
In my continued attempt at getting to grips with shell scripting and, one day, even perhaps writing a shell script that does something useful, I'm writing this note about looping.
The shell 'for' goes through each item on a list in turn, exactly the same as perl really. So:
for var in 1 2 3 4 5; do echo $var done
will print out
1 2 3 4 5
Which is all very fascinating. Perhaps more usefully, we can use a glob to process every file in the current directly, so:
for file in *; do echo $file done
will list every file in the current working directory, because the '*' is expanded by bash to all files in the directory. Of course, this does the same as the 'ls' command.
Slightly more useful might be something like this:
for file in *~; do mv $file ~/Backups/ done
which moves all the files ending in '~' to a directory named 'Backups'.
More on loops later. In the meantime, there's a great page on it here.