LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-31-2014, 03:43 AM   #1
hahacc
Member
 
Registered: Oct 2010
Posts: 87

Rep: Reputation: 1
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.
 
Old 03-31-2014, 03:56 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
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.

Last edited by evo2; 03-31-2014 at 03:58 AM. Reason: 99 or 100?
 
Old 03-31-2014, 04:00 AM   #3
hahacc
Member
 
Registered: Oct 2010
Posts: 87

Original Poster
Rep: Reputation: 1
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 View Post
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.
 
Old 03-31-2014, 04:03 AM   #4
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

what shell are you using?

Evo2.
 
Old 03-31-2014, 04:14 AM   #5
hahacc
Member
 
Registered: Oct 2010
Posts: 87

Original Poster
Rep: Reputation: 1
Hi Evo2,
I'm using bash. I tried ksh, but the same result.


Quote:
Originally Posted by evo2 View Post
Hi,

what shell are you using?

Evo2.
 
Old 03-31-2014, 04:28 AM   #6
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
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.
 
Old 03-31-2014, 04:49 AM   #7
hahacc
Member
 
Registered: Oct 2010
Posts: 87

Original Poster
Rep: Reputation: 1
Thumbs up

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 View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash: nested brace expansions porphyry5 Programming 3 06-02-2012 03:05 PM
[SOLVED] Bash - brace expansion using variable student04 Linux - Software 2 03-24-2010 03:26 PM
Brace expansion: does this kind exist? exscape Linux - Software 4 04-28-2009 04:45 AM
Avoiding Shell Script Brace Expansion Woodsman Slackware 4 05-31-2008 10:36 AM
bash: extra stuff in brace expansion jhwilliams Programming 4 09-07-2007 03:44 AM


All times are GMT -5. The time now is 01:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration