user3472065
user3472065

Reputation: 1399

Bash command in ruby script - Error "Command not found"

I need to run a bash command (ls -al) in my ruby script. This command is launched in different folders that start with the letters "my".

Dir.glob("#{PATH_TO_SEARCH}/my*",File::FNM_CASEFOLD) do |path|

    command = path + "/ls -al"
    output_result = (%x(#{command}))

end

I receive a strange error:

"command not found: /home/user/my123/ls -al"
"command not found: /home/user/my222/ls -al"
"command not found: /home/user/my423/ls -al"

The iteration goes well. The problem is the command

Upvotes: 0

Views: 218

Answers (1)

Marek Lipka
Marek Lipka

Reputation: 51181

You generate your commands inproperly. It should be:

command = 'ls -al ' + path

Upvotes: 2

Related Questions