# How to enable inspec.command('ls') on kitchen-docker?

**URL:** <https://discourse.chef.io/t/how-to-enable-inspec-command-ls-on-kitchen-docker/9558>\
**Category:** Chef InSpec\
**Created:** [September 30, 2016, 10:32pm UTC](https://discourse.chef.io/t/how-to-enable-inspec-command-ls-on-kitchen-docker/9558 "2016-09-30T22:32:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Victor](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/victor/32/1259_2.png) [@Victor](https://discourse.chef.io/u/Victor)\
**Post date:** [September 30, 2016, 10:32pm UTC](https://discourse.chef.io/t/how-to-enable-inspec-command-ls-on-kitchen-docker/9558/1 "2016-09-30T22:32:16Z")

</div>

Per the following page,  
[http://inspec.io/docs/reference/ruby\_usage/](http://inspec.io/docs/reference/ruby_usage/)

I should be able to run the following in my …/cook\_book/test/integration/default/inspec/default\_inspe.rb  
inspec.command(‘ls’)

But I got  
undefined local variable or method `inspec’

How to fix this?

---

<div class="post-metadata">

**Author:** ![chris-rock](https://avatars.discourse-cdn.com/v4/letter/c/e9c0ed/32.png) [@chris-rock](https://discourse.chef.io/u/chris-rock)\
**Post date:** [October 17, 2016, 11:45am UTC](https://discourse.chef.io/t/how-to-enable-inspec-command-ls-on-kitchen-docker/9558/2 "2016-10-17T11:45:38Z")

</div>

Hi @Victor I am not sure I understand what failed. In your test, your can check for ls in your inspec test

```auto
describe command('ls') do
  its('stdout') { should_not eq ''}
end

```

Is that answering your question?

---

<div class="post-metadata">

**Author:** ![Victor](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/victor/32/1259_2.png) [@Victor](https://discourse.chef.io/u/Victor)\
**Post date:** [October 17, 2016, 9:40pm UTC](https://discourse.chef.io/t/how-to-enable-inspec-command-ls-on-kitchen-docker/9558/3 "2016-10-17T21:40:34Z")

</div>

chris-rock, what I wanted to do was to obtain file names during compile time. Then use the file names during execution time.  
The code in your reply won’t run until execution time. I can’t use its stdout in another resource block such as describe file.

---

<div class="post-metadata">

**Author:** ![apop](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@apop](https://discourse.chef.io/u/apop)\
**Post date:** [October 18, 2016, 12:09pm UTC](https://discourse.chef.io/t/how-to-enable-inspec-command-ls-on-kitchen-docker/9558/4 "2016-10-18T12:09:02Z")

</div>

Hi Victor,

`inspec.command` is called from the resource code. If you want to run a command, use the `command` resource that Chris pointed out. InSpec has only one phase of execution. I believe the code you are looking for looks like this:

```ruby
apache_files = command('ls -d /etc/apache2/*').stdout.split("\n")

apache_files.each { |apache_file|
  describe file(apache_file) do
    its('owner') { should eq 'root'}
  end
}

```

It gives me the following output:

```auto
$ inspec exec ~/tmp/a.rb

Target: local://

  File /etc/apache2/extra
     ✔ owner should eq "root"
  File /etc/apache2/httpd.conf
     ✔ owner should eq "root"
  File /etc/apache2/magic
     ✔ owner should eq "root"

Test Summary: 3 successful, 0 failures, 0 skipped

```

Hope this helps,  
Alex

---

<div class="post-metadata">

**Author:** ![Victor](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/victor/32/1259_2.png) [@Victor](https://discourse.chef.io/u/Victor)\
**Post date:** [November 4, 2016, 1:28pm UTC](https://discourse.chef.io/t/how-to-enable-inspec-command-ls-on-kitchen-docker/9558/5 "2016-11-04T13:28:36Z")

</div>

Worked. Thanks!
