Reputation: 1345
Here is the code do.rb
:
#!/usr/bin/ruby
def open
fp = File.open("input")
yield fp
fp.close
end
open do |fp|
while line = fp.gets
puts `du #{line} -h`
# puts `du -h #{line}` # this works fine
end
end
And the input
file:
1.rb
2.rb
If I run ruby do.rb
, it just returns a command not found
.
And I have to change -h
before #{line}
.
I don't why. Thanks.
Upvotes: 1
Views: 164
Reputation: 369424
A string returned by IO#gets
contains line separator.
You should remove the line separator using String#chomp
:
puts `du #{line.chomp} -h`
Upvotes: 2