Issue
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?
Solution
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)}
Answered By - Dmitri Chubarov Answer Checked By - Dawn Plyler (WPSolving Volunteer)