问题
Today, I tried to call a script from ruby. I did like this:
`./aaa.sh`,
but it returned 'command not found', here is the session log of irb:
irb(main):012:0> `which aaa.sh`
=> "/root/rocky/aaa.sh\n"
irb(main):013:0> `aaa.sh`
(irb):13: command not found: aaa.sh
=> ""
irb(main):014:0> `./aaa.sh`
(irb):14: command not found: ./aaa.sh
=> ""
But, if I call it as 'sh aaa.sh', it works.
irb(main):015:0> `sh aaa.sh`
=> "aaa.sh\ntest.rb\n"
so, what's wrong whith this?
回答1:
A couple possibilities immediately come to mind:
- Your
aaa.sh
file doesn't have execute permission. - Your
aaa.sh
file doesn't start with#!/bin/sh
so the OS doesn't know how to execute it.
As an aside, are you really experimenting while logged in as root? That's a quick and easy way to have a really bad day.
来源:https://stackoverflow.com/questions/8074515/command-not-found-when-i-call-myshell-in-ruby