I have a script in which I need to test a variable to see if it consists of a 7 digit number (possibly starting with 0) followed by a dash and a number of 1,2 or 3 digits. For example:
6912054-3
0156924-103
I have used
[[ $num = [0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9]* ]]
and so far gotten away with it, since in my application it is very rare to see anything other than 1 or 2 more digits after the first in the "dash number". But I would like a solution which is exact, and preferably elegant!
Also, can anyone tell me where I can find a reference on how to use [[ ]]? While I can find information on the ordinary "test" or [ ] command, nothing I have seen has ever said more than "you can also use double brackets". What little I know about them I gleaned from other people's scripts!
6912054-3
0156924-103
I have used
[[ $num = [0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9]* ]]
and so far gotten away with it, since in my application it is very rare to see anything other than 1 or 2 more digits after the first in the "dash number". But I would like a solution which is exact, and preferably elegant!
Also, can anyone tell me where I can find a reference on how to use [[ ]]? While I can find information on the ordinary "test" or [ ] command, nothing I have seen has ever said more than "you can also use double brackets". What little I know about them I gleaned from other people's scripts!