[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Learning experience with BASH



> What I have learned is that BASH pukes on a blank new line in a script

I think you mean as the first line. As a shell, it looks at the first line
to determine what shell the script was written in. If your shell is a BASH
script, it will use the first line to declare this.

This first line is often called the "Shebang" line, and I'll just say that
I'm old enough to know from whence it comes. It's the line you see at the
top of any script:

#!/usr/bin/bash

This is NOT to be confused with scripts written for other shells, such as:

#!/usr/bin/ksh
#!/usr/bin/sh
#!/usr/bin/perl
#!/usr/bin/zsh
..

Only the FIRST line works. The above were examples, not a literal script.

> the underscore seems to have some special meaning in a directory/filename_tag
> listing.

Here's a revised script:

#!/usr/bin/bash
# thumbnailer.sh
# script to resize candle pics and include resolution in name
# Feb 13, 2004 mjw (with help)
#
# Usage: ls directory_with_images | thumbnailer.sh
#
# Define a function that does all the hard work
resize() {
  local fname=$1

   # No file and we are done
  [ ! -f "${fname}/${fname}-2048x1536.jpg" ] && return

  # Convert 2048x1536 to 1024x768 (desktop)
  jpegtopnm "${fname}/${fname}-2048x1536.jpg" | \
    pnmscale -xsize 1024 -ysize 768 | \
    pnmtojpeg > "${fname}/${fname}-1024x768.jpg"

  # Convert 2048x1536 to 128x96 (thumbnail)
  jpegtopnm "${fname}/${fname}-2048x1536.jpg" | \
    pnmscale -xsize 128 -ysize 96 | \
    pnmtojpeg > "${fname}/${fname}-128x96.jpg"
}
#
# Read the filenames from STDIN
while read line
do
  echo resizing "${line}/${line}-2048x1536.jpg"
  resize $line
done
# FIN

Mike/

---------------------------------------------
http://www.valuenet.net



-
To unsubscribe, send email to majordomo@silug.org with
"unsubscribe silug-discuss" in the body.