[wellylug] BASH scripting help required
Michael Robinson
michael at diaspora.gen.nz
Fri May 7 20:23:30 NZST 2004
On Fri, May 07, 2004 at 10:55:42AM +1200, Jamie Dobbs wrote:
> I have a script that does some file manipulation then sends a file out of
> the serial port.
> Each file is reference as $file (via a for 'file in <filespec>' type setup).
> What I need to do is to be able to test on the first character of the
> filename and process something accordingly - ie. if the first character is
> 'L' then do one thing, if it is 'P' do another etc. My skills at string
> manipulation in Unix/BASH are terrible (at best) and I wonder if someone
> caqn give me some pointers on how to do this.
for file in <filespec>
do
case $file in
[Ll]*)
# do L things
;;
[Pp]*)
# do P things
;;
[Oo]*)
# do O things
;;
*)
echo "Don't know how to handle file $file" 1>&2
;;
esac
done
More information about the wellylug
mailing list