diff options
author | Akinori MUSHA <[email protected]> | 2020-06-16 23:15:51 +0900 |
---|---|---|
committer | Akinori MUSHA <[email protected]> | 2020-06-16 23:15:51 +0900 |
commit | 68e43103442b95ebfa133e238550159fc3d1197d () | |
tree | 8467f2d4ae9397e98da711ae1d1107272cf7237b /lib/shellwords.rb | |
parent | 318d52e820c9ed1bc4c12aa97af49a89953649bc (diff) |
Improve the document of Shellwords
- Improve careless examples - Insert `--` before a file name for cat(1) - Insert `-e` before a search pattern for grep(1) - Add a caution about passing an arbitrary argument to a command
-rw-r--r-- | lib/shellwords.rb | 35 |
1 files changed, 22 insertions, 13 deletions
@@ -24,28 +24,37 @@ # argv = "see how they run".shellsplit # argv #=> ["see", "how", "they", "run"] # -# Be careful you don't leave a quote unmatched. # # argv = "they all ran after the farmer's wife".shellsplit # #=> ArgumentError: Unmatched double quote: ... # -# In this case, you might want to use Shellwords.escape, or its alias -# String#shellescape. # -# This method will escape the String for you to safely use with a Bourne shell. # -# argv = Shellwords.escape("special's.txt") -# argv #=> "special\\'s.txt" -# system("cat " + argv) # # Shellwords also comes with a core extension for Array, Array#shelljoin. # -# argv = %w{ls -lta lib} -# system(argv.shelljoin) # -# You can use this method to create an escaped string out of an array of tokens -# separated by a space. In this example we used the literal shortcut for -# Array.new. # # === Authors # * Wakou Aoyama @@ -123,7 +132,7 @@ module Shellwords # # # Search files in lib for method definitions # pattern = "^[ \t]*def " - # open("| grep -Ern #{pattern.shellescape} lib") { |grep| # grep.each_line { |line| # file, lineno, matched_line = line.split(':', 3) # # ... |