Reputation: 882
currDir = ""
#
# regex is from stack overflow question:
dirRegex = Regexp.new '^(?!.*[\\/]\.{2}[\\/])(?!\.{2}[\\/])[-\w.\\/]+$'
if ARGV.length == 1 && $1.to_s.match dirRegex
currDir = $1
puts $1
puts "#{currDir}"
puts ARGV.length
else
currDir = "./"
puts $1
puts "#{currDir}"
puts ARGV.length
end
When I try to have the above code match a directory such as home or ~/test/ it gives me an error.
./script.rb /home/local/NKU/dixonc3/test
./script.rb:9: syntax error, unexpected tIDENTIFIER, expecting keyword_then or ';' or '\n'
./script.rb:14: syntax error, unexpected keyword_else, expecting $end
Upvotes: 0
Views: 45
Reputation: 33626
Change:
if ARGV.length == 1 && $1.to_s.match dirRegex # line 5
to:
if ARGV.length == 1 && $1.to_s.match(dirRegex)
Upvotes: 5