0

I obtain a different behavior when I call Bash string removal inside a script rather than directly in shell.

My case, running that directly in console:

id="00902"
echo ${id##+(0)}

output:

902

But, running this script, in a file

#!/bin/bash
id="00902"
echo ${id##+(0)}

Output:

00902

What am I missing?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
Ealrann
  • 368
  • 1
  • 15

1 Answers1

4

To have +(0) expansion you need extglob option to be set. By default it is set in an interactive shell, but is not set in scripts. You can check if it is set with shopt command.

The following should work

#!/bin/bash
shopt -s extglob
id="00902"
echo ${id##+(0)}
Dima Chubarov
  • 16,199
  • 6
  • 40
  • 76