[X-Unix] bash problem: `expr index $somestring somepattern` fails

Eugene list-themacintoshguy at fsck.net
Sat Oct 30 01:42:10 PDT 2004


On Sat, Oct 30, 2004 at 09:48:28AM +0200, Steffen Lund Hokland wrote:
: 
: I'm writing a bash script and needed something along the lines of:
: 
: `expr index $somestring somepattern`
: 
: for parsing a text string. This is described in:
: 'Advanced Bash-Scripting Guide: An in-depth exploration of the art of 
: shell scripting' version 2.7.7. However when running the command above 
: i get an error:
: 
: expr: syntax error

I'm not familiar with this use of expr(1).  It doesn't appear to be
a built-in bash command.  For strings, the only use I know of is:

	$ expr expression1 : expression2

For example:

	$ expr foo : '.*'
	3
	$ expr /usr/X11R6/bin/xbiff : '.*/\(.*\)'
	xbiff


-- 
Eugene Lee
http://www.coxar.pwp.blueyonder.co.uk/


More information about the X-Unix mailing list