mirror of
https://github.com/chubin/cheat.sheets
synced 2024-11-19 03:25:44 +00:00
add note on ruby -l switch
Quite a useful switch for one-liners
This commit is contained in:
parent
ed061663ba
commit
10313bda28
@ -13,6 +13,10 @@ ruby -e 'puts "Hello world"'
|
||||
# end
|
||||
ruby -ne 'puts $_' file.txt
|
||||
|
||||
# Beware that with the -n switch $_ contains newline character in the end.
|
||||
# With the addition of -l switch each line read has the newline character removed.
|
||||
ls | ruby -lne 'File.rename($_, $_.upcase)'
|
||||
|
||||
# The -p switch acts similarly to -n, in that it loops over each of the lines in the input
|
||||
# after your code has finished, it always prints the value of $_
|
||||
# Example: replace e with a
|
||||
|
Loading…
Reference in New Issue
Block a user