Hi, Can you bit help me to understand how the below options work in real life? -T [level] -K [ kcode] -F pat -i [ ext] Thanks in advance!
on 2013-01-11 13:03
on 2013-01-11 13:18
http://www.tutorialspoint.com/ruby/ruby_command_li... To the best of my knowledge (someone please correct me if I'm wrong) -T: Sets a level that determines how "paranoid" it should be about "tainted" input. You can use this to avoid users keying in malicious input. I think it's mainly used when you're running "eval" statements on user input. -K: Determines what kind of character set you're using. Some characters may not be valid if you're using the wrong set. -F: Never used this but according to the above link it just lets you specify the default seperator when using the "split" method. -i: looks like you can specify a file to output to. Not so sure about this one.
on 2013-01-11 13:22
On Fri, 11 Jan 2013 13:03:28 +0100, Arup Rakshit <lists@ruby-forum.com> wrote: > Hi, > > Can you bit help me to understand how the below options work in real > life? > > -T [level] This one controls tainting, which is a bolted-on feature that no one ever uses as far as I know. It is supposed to help prevent security holes, but like PHP's magic_quotes isn't a real solution. > -K [ kcode] I think this is 1.8 only (or at least I can't find it in Ruby 1.9's `ruby -h` output). It was something encoding-related. > -F pat > > -i [ ext] These would generally be used with -e, for one-off magic one-liners. You probably won't find them in real life code either.
on 2013-01-11 13:29
Joel Pearson wrote in post #1091897: > http://www.tutorialspoint.com/ruby/ruby_command_li... > > To the best of my knowledge (someone please correct me if I'm wrong) > > -T: Sets a level that determines how "paranoid" it should be about > "tainted" input. You can use this to avoid users keying in malicious > input. I think it's mainly used when you're running "eval" statements on Any small code snippet if you have, could you please share? Thanks
on 2013-01-11 13:43
Joel Pearson wrote in post #1091900:
> Try this: http://www.ruby-doc.org/docs/ProgrammingRuby/html/taint.html
Joel, you are Awesome! Nice material you have posted. :)
thanks as usual to you for your interest in my pain! :)
on 2013-01-11 19:07
Bartosz Dziewoński wrote in post #1091898: > On Fri, 11 Jan 2013 13:03:28 +0100, Arup Rakshit <lists@ruby-forum.com> > wrote: >> -F pat >> >> -i [ ext] > Can any one help me to understand how the above two options work in Ruby? Thanks,
on 2013-01-11 20:32
On Fri, Jan 11, 2013 at 12:07 PM, Arup Rakshit <lists@ruby-forum.com>
wrote:
> Ruby?
They are all used primarily for one-liners (i.e. invocations where a
script is specified as a string on the command line after -e); the
switches in question closely mirror those present in perl, awk, and
sed.
-F is for use only with -a; -a in turn is for use only with -n or -p.
-n and -p take the script that's the argument to -e and wrap it in a
loop. The loop is equivalent to `while gets; <SCRIPT> end`; the `gets`
puts the line read into the variable $_. The difference between the
two is that -p prints each line read, while -n doesn't. (Throught
experimentation, I just found out $_ gets printed at the *end* of each
loop iteration; so if you modify $_ inside the loop, it will print the
modified version.)
-a causes Ruby to automatically split each line read into $_; the
result goes into $F, an array.
-F lets you specify the separator to be used by -a.
Thus, if we have a file foo:
foo:bar:foo
and we use the command line:
$ ruby -a -F: -n -e 'p $F' foo
we get the output:
["foo", "bar", "foo\n"]
Now, -i is used to make changes to files supplied on the command line,
without having to code that specifically in the script. The argument
to -i specifies a filename extension to append to the filename(s), to
back up the old file(s). Thus if we have the above file foo and
another file named bar, with the contents:
bar:foo:bar
and we use the command line:
$ ruby -i~ -p -e "$_.gsub!(/bar/, 'baz')" foo bar
we will end up with these files:
foo~:
foo:bar:foo
bar~:
bar:foo:bar
foo:
foo:baz:foo
bar:
baz:foo:baz
`ruby -h` (at least in 1.9.3) implies that you can use -i without an
extension, in which case no backup will be made; but I can't get it to
accept -i without an extension at the moment:
$ ruby -i -p -e "$_.gsub!(/bar/, 'baz')" foo bar
-e:1:in `gets': Can't do inplace edit without backup (fatal)
from -e:1:in `gets'
from -e:1:in `<main>'
Obviously though it's a good idea to keep a backup.
on 2013-01-11 20:50
Eric Christopherson wrote in post #1091980: > On Fri, Jan 11, 2013 at 12:07 PM, Arup Rakshit <lists@ruby-forum.com> > wrote: >> Ruby? Excellent logic you just have provided to me!Exactly what or more than what I was looking for. Thank you very much!
on 2013-01-12 14:17
On Fri, Jan 11, 2013 at 6:22 AM, Matma Rex <matma.rex@gmail.com> wrote: > These would generally be used with -e, for one-off magic one-liners. You > probably won't find them in real life code either. My one-liners are my life :)
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.