[TxMt] run script with args
Paul McCann
paul.mccann at adelaide.edu.au
Sat Oct 14 07:03:33 UTC 2006
Allan wrote,
>> [...] but how do I run the script I'm looking at, with arguments?
>> [...]
>
> No way to do that, my reply form last time this came up http://
> lists.macromates.com/pipermail/textmate/2006-September/013015.html
Perhaps I'm missing the point here (seems to be a habit these days),
but how about mimicking things by pushing onto ARGV at the top of the
script? That is, use something like
ARGV.concat(%w(/etc/file1 /Users/pmccann/file2))
For example:
=======================================================================
#!/usr/bin/env ruby -w
ARGV.concat(%w(/etc/passwd /Users/pmccann/.zshrc)) # Stack 'em on...
# And now use ARGV as per usual...
ARGV.each do |file|
str = IO.readlines(file)
puts "\nThere are #{str.length} lines in #{file}"
puts "Here are the first 5:"
puts "#{str[0..4]}\n"
end
=======================================================================
That seems to run identically (under command-R) to what happens if I
save the "unstacked" version into file.rb and use
./file.rb /etc/passwd /Users/pmccann/.zshrc
on the command line.
Regards,
Paul
More information about the textmate
mailing list