From: -j b- Date: 2008-05-07T01:27:10+09:00 Subject: Re: Escaped characters from the command-line Albert Schlef wrote: > -j b- wrote: >> I am working on a parser that allows the user to provide a delimiter as >> an argument to the script. However, I can not find a way to [elegantly] >> handle escaped characters (such as \t and \n). >> A simplified example to illustrate: >> >> # Using >> s = ARGV.shift >> puts ['west', 'side', story'].join(s) >> >> $ ./parse.rb '\t' >> => west\tside\tstory > > It isn't a Ruby issue. It's a shell one. You need to find out how it's > possible, in your shell, to specify those special characters. Are you > using Linux? Bash? Yes. Yes. But the idea is that it shouldnt matter. > > So there are at least three ways to do \n in bash. I know that it possible, from a user standpoint, to input a special character in multiple ways. My concern is that I dont want to force that restriction on the user. For example, the utility tr will accept '\t' as a single character; I find this ultimately more useful than tr '^v[tab]' ' ' (or any of the above mentioned methods). If it is a shell issue then I am forced to modify the arguments accordingly. However, I'm still looking for a more elegant way then the heavy case statement. I've experimented with a gsub! solution but the way backslashes are escaped in regular expressions (particularly when reinserting into a string) has me blocked at the moment. Thanks. j -- Posted via http://www.ruby-forum.com/.