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!
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!
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 Fri, 11 Jan 2013 13:03:28 +0100, Arup R. [email protected]
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.
Joel P. wrote in post #1091897:
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
Joel P. wrote in post #1091900:
Try this: Programming Ruby: The Pragmatic Programmer's Guide
Joel, you are Awesome! Nice material you have posted.
thanks as usual to you for your interest in my pain!
Bartosz Dziewoński wrote in post #1091898:
On Fri, 11 Jan 2013 13:03:28 +0100, Arup R. [email protected]
wrote:
-F pat
-i [ ext]
Can any one help me to understand how the above two options work in
Ruby?
Thanks,
Eric C. wrote in post #1091980:
On Fri, Jan 11, 2013 at 12:07 PM, Arup R. [email protected]
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 Fri, Jan 11, 2013 at 12:07 PM, Arup R. [email protected]
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 `’
Obviously though it’s a good idea to keep a backup.
On Fri, Jan 11, 2013 at 6:22 AM, Matma R. [email protected] 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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs