I have a script that includes the following line:-

[ ${@:0-2:1} = '.' ] || echo

but after displaying the text I get

Segmentation fault

If I run the same code on the command line I don't get the error.

If I change the substr code in the script to

${@:0-2}

it's OK - no error, but of course isn't doing what I want.
So what can be the problem that causes the error only when in a shell script, but not otherwise?

Come to think of it, what's a segmentation fault?