You were right. It is not a bug in your script. Read on.
David Drum wrote:
Kenneth Whittaker penned:
Try putting quotes around .snapshot/*/NeXT/Apps/Icon.app/help/.list and see what happens.
Why would I want to put quotes around a file specification that contains a wildcard? That would cause it to look for a directory named "*". That is why I have .snapshot/*/"&" in the sed expression.
kenw-sun - 08:48:25 PM - 13 % find * -type f -print | sed -e 's%.*%ls -ldtr "&" .snapshot/*/"&"; echo%' | bash > messed.up.files .snapshot/*/france/snoop.out: No such file or directory .snapshot/*/france/eacces.txt: No such file or directory .snapshot/*/france/er357.tmp_mail: No such file or directory .snapshot/*/france/messed.up.files: No such file or directory
Now I will pick "france/snoop.out" and leave out the "| bash > messed.up.files"
find france/snoop.out -type f -print | sed -e 's%.*%ls -ldtr "&" .snapshot/*/"&"; echo%' ls -ldtr "france/snoop.out" .snapshot/*/"france/snoop.out"; echo
Now, what happens when bash gets this?
kenw-sun - 08:57:11 PM - 2 % bash bash$ ls -ldtr "france/snoop.out" .snapshot/*/"france/snoop.out"; echo .snapshot/*/france/snoop.out: No such file or directory -rw-rw-r-- 1 kenw engineer 2150548 May 19 01:28 france/snoop.out
bash$ ls "france/snoop.out" france/snoop.out bash$ ls .snapshot/*/"france/snoop.out" .snapshot/*/france/snoop.out: No such file or directory
bash$ ls .snapshot/*/france/snoop.out .snapshot/hourly.0/france/snoop.out .snapshot/hourly.1/france/snoop.out .snapshot/hourly.2/france/snoop.out .snapshot/hourly.3/france/snoop.out .snapshot/hourly.4/france/snoop.out .snapshot/hourly.5/france/snoop.out .snapshot/hourly.6/france/snoop.out .snapshot/nightly.0/france/snoop.out .snapshot/nightly.1/france/snoop.out .snapshot/snapshot_for_dump.1/france/snoop.out
Try Bourne shell:
bash$ sh $ ls .snapshot/*/"france/snoop.out" .snapshot/hourly.0/france/snoop.out .snapshot/hourly.1/france/snoop.out .snapshot/hourly.2/france/snoop.out .snapshot/hourly.3/france/snoop.out .snapshot/hourly.4/france/snoop.out .snapshot/hourly.5/france/snoop.out .snapshot/hourly.6/france/snoop.out .snapshot/nightly.0/france/snoop.out .snapshot/nightly.1/france/snoop.out .snapshot/snapshot_for_dump.1/france/snoop.out
Woah! I think you just found a bash bug.
Let me try a slight mutation of your script: kenw-sun - 08:57:11 PM - 4 % find * -type f -print | sed -e 's%.*%ls -ldtr "&" .snapshot/*/"&"; echo%' | sh > messed.up.files kenw-sun - 08:57:11 PM - 5 %
Ta da! No errors. It looks like bash has some subtle confusion with expansion of * and quotes. It only happens with a small number of files.
I will try copying the data OUTSIDE of the snapshots: kenw-sun - 09:28:34 PM - 50 % tar cf - blah | ( cd junk; tar xf - ) kenw-sun - 09:29:34 PM - 54 % find * -type f -print | sed -e 's%.*%ls -ldtr "&" ../junk/*/"&"; echo%' | bash > messed.up.files ../junk/*/france/snoop.out: No such file or directory ../junk/*/france/eacces.txt: No such file or directory ../junk/*/france/er357.tmp_mail: No such file or directory ../junk/*/france/messed.up.files: No such file or directory ../junk/*/ifstat/ifstat.txt: No such file or directory
Now lets try on local disk! kenw-sun# mkdir /ld1 kenw-sun# mkdir /ld2 kenw-sun# tar cf - blah | (cd /ld1; tar xf - ) kenw-sun# tar cf - blah | (cd /ld2; tar xf - ) kenw-sun# cd /ld1/blah kenw-sun# find * -type f -print | sed -e 's%.*%ls -ldtr "&" /ld2/*/"&"; echo%' | bash > messed.up.files /ld2/*/france/snoop.out: No such file or directory /ld2/*/france/eacces.txt: No such file or directory /ld2/*/france/er357.tmp_mail: No such file or directory /ld2/*/france/messed.up.files: No such file or directory /ld2/*/news/lisa93.ps: No such file or directory /ld2/*/news/news.people: No such file or directory /ld2/*/news/netlink.txt: No such file or directory /ld2/*/news/idt.txt: No such file or directory /ld2/*/news/news_tan.txt: No such file or directory /ld2/*/news/README: No such file or directory /ld2/*/news/sysconfig: No such file or directory /ld2/*/news/erinet.txt: No such file or directory /ld2/*/news/gte.txt: No such file or directory /ld2/*/news/large_directory.txt: No such file or directory /ld2/*/news/tr-bravetoaster.ps: No such file or directory
Wow! It's even worse on local disk. The workaround is to use "sh" instead of bash. If you are using Linux, then it is probably the bug discoverer's responsibility to fix it :)
kenw-sun - 08:00:31 PM - 40 % find * -type f -print | sed -e 's%.*%ls -ldtr "&" .snapshot/*/"&"; echo%' | bash > messed.up.files .snapshot/*/france/snoop.out: No such file or directory .snapshot/*/france/eacces.txt: No such file or directory .snapshot/*/france/er357.tmp_mail: No such file or directory .snapshot/*/france/messed.up.files: No such file or directory
kenw-sun - 08:00:31 PM - 42 % ls -ldtr ".snapshot/*/france/snoop.out" .snapshot/*/france/snoop.out: No such file or directory
Of course - .snapshot contains hourly.?, weekly.?, etc.
I think my question is still a valid one. For example, the following works, even though it does not differ in essence from my original example which does not:
find * -type f -print | \ sed -e 's%.*%ls -ldtr "&" .snapshot/{hourly.{0,1},nightly.{0,1},weekly.{0,1}}/"&"; echo%' | \ bash > messed.up.files
[I have shortened the list of snapshot directories for brevity.]
David Drum wrote:
Hello everyone,
I am quite perplexed by the behavior I am seeing below:
david@vortex ~ $ find * -type f -print | sed -e 's%.*%ls -ldtr "&" .snapshot/*/"&"; echo%' | bash > messed.up.files .snapshot/*/Mail/.dir.tiff: No such file or directory .snapshot/*/NeXT/Apps/.dir.tiff: No such file or directory .snapshot/*/NeXT/Apps/.opendir.tiff: No such file or directory .snapshot/*/NeXT/Apps/Icon.app/brushes/.places: No such file or directory .snapshot/*/NeXT/Apps/Icon.app/help/.places: No such file or directory .snapshot/*/NeXT/Apps/Icon.app/help/.list: No such file or directory ^C david@vortex ~ $ ls -l .snapshot/*/NeXT/Apps/Icon.app/help/.list -rw-r--r-- 1 david staff 1095 Nov 14 1992 .snapshot/hourly.0/NeXT/Apps/Icon.app/help/.list -rw-r--r-- 1 david staff 1095 Nov 14 1992 .snapshot/hourly.1/NeXT/Apps/Icon.app/help/.list -rw-r--r-- 1 david staff 1095 Nov 14 1992 .snapshot/hourly.2/NeXT/Apps/Icon.app/help/.list -rw-r--r-- 1 david staff 1095 Nov 14 1992 .snapshot/hourly.3/NeXT/Apps/Icon.app/help/.list -rw-r--r-- 1 david staff 1095 Nov 14 1992 .snapshot/weekly.0/NeXT/Apps/Icon.app/help/.list
Would anyone care to comment? This is greatly disturbing.
Regards,
David K. Drum david@more.net -- "That man has a rare gift for obfuscation." -- ST:DS9 * "It's hard to be bored when you're as stupid as a line." -- Vernor Vinge * "Reality has a tendency to be so uncomfortably real." -- Neil Peart * "You can only measure the size of your head from the inside." -- Larry Wall