LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bash brace expansion won't output two zero (https://www.linuxquestions.org/questions/linux-newbie-8/bash-brace-expansion-wont-output-two-zero-4175500007/)

hahacc 03-31-2014 02:43 AM

bash brace expansion won't output two zero
 
Hi all,
I found one issue when using bash brace expansion.
I want to output test0050 to test0100, so I used following:

[root@centos-doxer pping]# echo test0{050..100}
test050 test051 test052 test053 test054 test055 test056 test057 test058 test059 test060 test061 test062 test063 test064 test065 test066 test067 test068 test069 test070 test071 test072 test073 test074 test075 test076 test077 test078 test079 test080 test081 test082 test083 test084 test085 test086 test087 test088 test089 test090 test091 test092 test093 test094 test095 test096 test097 test098 test099 test0100

However, as you may see, test050 to test099 was the result, while what I want is test0050 to test0099.

Could any one help on this?

Thanks.

evo2 03-31-2014 02:56 AM

Hi,

try
Code:

echo test{0050..0099}
or more trivially
Code:

echo test00{50..99}
or to 100
Code:

echo test{0050..0100}
HTH,

Evo2.

hahacc 03-31-2014 03:00 AM

Thanks, but I tried:

Code:

echo test{0050..0100}
The output is:

Code:

[root@centos-doxer tmp]# echo test{0050..0100}
test50 test51 test52 test53 test54 test55 test56 test57 test58 test59 test60 test61 test62 test63 test64 test65 test66 test67 test68 test69 test70 test71 test72 test73 test74 test75 test76 test77 test78 test79 test80 test81 test82 test83 test84 test85 test86 test87 test88 test89 test90 test91 test92 test93 test94 test95 test96 test97 test98 test99 test100

And that's not what I expected.

Quote:

Originally Posted by evo2 (Post 5143956)
Hi,

try
Code:

echo test{0050..0099}
or more trivially
Code:

echo test00{50..99}
or to 100
Code:

echo test{0050..0100}
HTH,

Evo2.


evo2 03-31-2014 03:03 AM

Hi,

what shell are you using?

Evo2.

hahacc 03-31-2014 03:14 AM

Hi Evo2,
I'm using bash. I tried ksh, but the same result.


Quote:

Originally Posted by evo2 (Post 5143960)
Hi,

what shell are you using?

Evo2.


evo2 03-31-2014 03:28 AM

Hi,

sorry I should have asked what version. I know it works on 4.2 an greater, but I've seen it not work on 3.2. Check the section called "Brace Expansion" in the bash man page. If your version of bash supports this feature it should mention it. Eg from bash 4.3.0 man page:
Code:

      A  sequence  expression takes the form {x..y[..incr]}, where x and y are either inte‐
      gers or single characters, and incr, an optional  increment,  is  an  integer.  When
      integers  are supplied, the expression expands to each number between x and y, inclu‐
      sive.  Supplied integers may be prefixed with 0 to force each term to have  the  same
      width.  When either x or y begins with a zero, the shell attempts to force all gener‐
      ated terms to contain the same number of digits, zero-padding where necessary.

Evo2.

hahacc 03-31-2014 03:49 AM

Thanks a lot Evo2.

I tried on one CentOS 6.3 box with bash-4.1.2 and it worked as expected:

[root@centos63~]# rpm -qa|grep bash
bash-4.1.2-9.el6_2.x86_64
[root@centos63~]#
[root@centos63~]#
[root@centos63~]# echo test{0050..0100}
test0050 test0051 test0052 test0053 test0054 test0055 test0056 test0057 test0058 test0059 test0060 test0061 test0062 test0063 test0064 test0065 test0066 test0067 test0068 test0069 test0070 test0071 test0072 test0073 test0074 test0075 test0076 test0077 test0078 test0079 test0080 test0081 test0082 test0083 test0084 test0085 test0086 test0087 test0088 test0089 test0090 test0091 test0092 test0093 test0094 test0095 test0096 test0097 test0098 test0099 test0100

Quote:

Originally Posted by evo2 (Post 5143971)
Hi,

sorry I should have asked what version. I know it works on 4.2 an greater, but I've seen it not work on 3.2. Check the section called "Brace Expansion" in the bash man page. If your version of bash supports this feature it should mention it. Eg from bash 4.3.0 man page:
Code:

      A  sequence  expression takes the form {x..y[..incr]}, where x and y are either inte‐
      gers or single characters, and incr, an optional  increment,  is  an  integer.  When
      integers  are supplied, the expression expands to each number between x and y, inclu‐
      sive.  Supplied integers may be prefixed with 0 to force each term to have  the  same
      width.  When either x or y begins with a zero, the shell attempts to force all gener‐
      ated terms to contain the same number of digits, zero-padding where necessary.

Evo2.



All times are GMT -5. The time now is 06:24 PM.