Extract a string up to the first occurence of a substring

Hi,

I'm a newbie to shell scripting and have searched the forum but couldn't find what i was looking for.

Basically I have a list of filenames like...
123-fileone.txt

I want to be able to extract the prefix up to the first '-'. So I'd end up with 123. I have attempted it using a pretty basic regex ({F%-*}) but that trips up when there is more than 1 occurrence of '-' in the filename, which there can be.

I'm sure it's a simple thing to do...just not for me :slight_smile:

Thanks.

Kirk.

$ string="123-fileone.txt"
$ echo ${string%%-*}
123

Perfect! Thanks...

(Don't I feel stupid now :))