1

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.

1 Answer 1

2

A string returned by IO#gets contains line separator.

You should remove the line separator using String#chomp:

puts `du #{line.chomp} -h`
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.