From: Paul Lutus Date: 2006-10-03T15:50:12+09:00 Subject: Re: shell, ruby and regexp Une b辿vue wrote: > over Mac OS X the latest and ruby 1.8.4 i've found strange interferences > between the shell (in my case zsh) and arguments to a ruby script if one > of the args is a Regexp as for examples : > > /to.*/ - case 1 > /^Tit.*/ - case 2 > > > - case 1 (not the most seriaus) gave an answer from zsh BEFORE any > answer of my ruby script : > > ~/Desktop%> ruby test_args.rb /to.*/ > zsh: no matches found: /to.*/ This is a classic error in the use of a shell. You need to understand that your typing is interpreted first by the shell, and only then by Ruby. > > - case 2 seems to be DANGEROUS because it gaves me a kot of unexepected > args : > > ~/Desktop%> ruby test_args.rb /^Tit.*/ > /Applications/ > /Developer/ > /Library/ > /Network/ > /System/ > /Users/ > /Volumes/ > /automount/ > /bin/ > /cores/ > /dev/ > /etc/ > /opt/ > /private/ > /sbin/ > /tmp/ > /usr/ > /var/ > > > Notice i've discovered that when designing a small script in order to > delete files ))) > > Obviously i've found a workaround using quotes around the regexp : > > ~/Desktop%> ruby test_args.rb "to.*" > > but in that case i need another arg to my script in order to tell ruby > it is a regular expression. What's wrong with the original string enclosed in quotes? Instead of: ruby test_args.rb /to.*/ Type this instead: ruby test_args.rb "/to.*/" > > did someone have the same quirk ? I need to tell you something. Everyone who uses any variation on Unix (Unix, Linux, etc.) learns this right away about shell sessions. The solution is to get into the habit of using "irb" for little experiments, and writing a formal scripts for big experiments. Avoid typing things into the shell that it will interpret as wildcards. -- Paul Lutus http://www.arachnoid.com