[wellylug] BASH scripting help required

Tim Nicholas tim at nicholas.net.nz
Fri May 7 12:13:22 NZST 2004

On 07/05/04 10:55, 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.
> Cheers
> Jamie

Try something like this.

for file in yes no yellow fish; do
	if [ ${file:0:1} == "y" ]; then
		echo $file

Tim Nicholas                          ||                      Cilix
Email: tim at nicholas.net.nz            ||    Wellington, New Zealand
http://tim.nicholas.net.nz/           ||   Cell/SMS: +64 21 337 204

More information about the wellylug mailing list