Goliath!
May 30th, 2007, 03:30 AM
A long time ago in a galaxy far, far away I used to be pretty good with shell scripting. However, I'm seeing some strange behavior in bash on Feisty that I don't understand. Can some one explain it to me? Or is this some kind of bug?
I have a directory with lots of various files in it. I want to move a subset of these files to another directory. The files I want to move are all named YYYY-MM-DDab.tar.gz, where the YYYY-MM-DD is a date and ab stands for two alpha characters.
Here's what I tried in a test directory with a subset of my files.
1 me@pc:~/AAA_My_Stuff/regexp$ ls | sort
2 2007-05-27asdf
3 2007-05-27asdf.tar.gz
4 2007-05-27ff
5 2007-05-27ff.tar.gz
6 2007asdf
7 2007asdf.tar.gz
8 2asdf
9 2asdf.tar.gz
10 asdf
11 asdf.tar.gz
12
13 me@pc:~/AAA_My_Stuff/regexp$ ls [0-9]\{4,4\}*.tar.gz
14 ls: [0-9]{4,4}*.tar.gz: No such file or directory
15
16 me@pc:~/AAA_My_Stuff/regexp$ ls '[0-9]\{4,4\}*.tar.gz'
17 ls: [0-9]\{4,4\}*.tar.gz: No such file or directory
18
19 me@pc:~/AAA_My_Stuff/regexp$ ls [0-9]{4,4}*.tar.gz
20 ls: [0-9]4*.tar.gz: No such file or directory
21 ls: [0-9]4*.tar.gz: No such file or directory
22
23 me@pc:~/AAA_My_Stuff/regexp$ ls '[0-9]{4,4}*.tar.gz'
24 ls: [0-9]{4,4}*.tar.gz: No such file or directory
25
26 me@pc:~/AAA_My_Stuff/regexp$ ls [0-9]{0,4}*.tar.gz
27 ls: [0-9]4*.tar.gz: No such file or directory
28 2007-05-27asdf.tar.gz 2007-05-27ff.tar.gz 2007asdf.tar.gz
29
30 me@pc:~/AAA_My_Stuff/regexp$ ls '[0-9]{0,4}*.tar.gz'
31 ls: [0-9]{0,4}*.tar.gz: No such file or directory
32
33 me@pc:~/AAA_My_Stuff/regexp$ ls [0-9]\{0,4\}*.tar.gz
34 ls: [0-9]{0,4}*.tar.gz: No such file or directory
35
36 me@pc:~/AAA_My_Stuff/regexp$ ls '[0-9]\{0,4\}*.tar.gz'
37 ls: [0-9]\{0,4\}*.tar.gz: No such file or directory
Lines 1-11 are just to show you what's in my test directory.
Line 13 should work (according to my memory and all my old books and the info page). I should get a list of the files that start with exactly four digits and ending in .tar.gz. (I'm no longer checking for a whole date, just the year.) I need to escape the curly brackets with \. But I get nothing.
But maybe I need to quote the regular expression. So I try line 16 and get nothing.
But maybe I don't need to escape the curly brackets, so I try line 19 and I get nothing TWICE. What's going on here?
On line 23 I try to quote it again. Nope.
On line 26 I try to see if I could get a list with from zero to four digits at the beginning. This time I get nothing followed by a partially correct answer. But the file on line 9 should have matched and it's not listed. WTF????
On lines 30, 33, and 36 I tried some other combinations with no luck.
What am I missing here? Thanks in advance for anyone willing to help sort me out.
I have a directory with lots of various files in it. I want to move a subset of these files to another directory. The files I want to move are all named YYYY-MM-DDab.tar.gz, where the YYYY-MM-DD is a date and ab stands for two alpha characters.
Here's what I tried in a test directory with a subset of my files.
1 me@pc:~/AAA_My_Stuff/regexp$ ls | sort
2 2007-05-27asdf
3 2007-05-27asdf.tar.gz
4 2007-05-27ff
5 2007-05-27ff.tar.gz
6 2007asdf
7 2007asdf.tar.gz
8 2asdf
9 2asdf.tar.gz
10 asdf
11 asdf.tar.gz
12
13 me@pc:~/AAA_My_Stuff/regexp$ ls [0-9]\{4,4\}*.tar.gz
14 ls: [0-9]{4,4}*.tar.gz: No such file or directory
15
16 me@pc:~/AAA_My_Stuff/regexp$ ls '[0-9]\{4,4\}*.tar.gz'
17 ls: [0-9]\{4,4\}*.tar.gz: No such file or directory
18
19 me@pc:~/AAA_My_Stuff/regexp$ ls [0-9]{4,4}*.tar.gz
20 ls: [0-9]4*.tar.gz: No such file or directory
21 ls: [0-9]4*.tar.gz: No such file or directory
22
23 me@pc:~/AAA_My_Stuff/regexp$ ls '[0-9]{4,4}*.tar.gz'
24 ls: [0-9]{4,4}*.tar.gz: No such file or directory
25
26 me@pc:~/AAA_My_Stuff/regexp$ ls [0-9]{0,4}*.tar.gz
27 ls: [0-9]4*.tar.gz: No such file or directory
28 2007-05-27asdf.tar.gz 2007-05-27ff.tar.gz 2007asdf.tar.gz
29
30 me@pc:~/AAA_My_Stuff/regexp$ ls '[0-9]{0,4}*.tar.gz'
31 ls: [0-9]{0,4}*.tar.gz: No such file or directory
32
33 me@pc:~/AAA_My_Stuff/regexp$ ls [0-9]\{0,4\}*.tar.gz
34 ls: [0-9]{0,4}*.tar.gz: No such file or directory
35
36 me@pc:~/AAA_My_Stuff/regexp$ ls '[0-9]\{0,4\}*.tar.gz'
37 ls: [0-9]\{0,4\}*.tar.gz: No such file or directory
Lines 1-11 are just to show you what's in my test directory.
Line 13 should work (according to my memory and all my old books and the info page). I should get a list of the files that start with exactly four digits and ending in .tar.gz. (I'm no longer checking for a whole date, just the year.) I need to escape the curly brackets with \. But I get nothing.
But maybe I need to quote the regular expression. So I try line 16 and get nothing.
But maybe I don't need to escape the curly brackets, so I try line 19 and I get nothing TWICE. What's going on here?
On line 23 I try to quote it again. Nope.
On line 26 I try to see if I could get a list with from zero to four digits at the beginning. This time I get nothing followed by a partially correct answer. But the file on line 9 should have matched and it's not listed. WTF????
On lines 30, 33, and 36 I tried some other combinations with no luck.
What am I missing here? Thanks in advance for anyone willing to help sort me out.