2016-09-22 12:43:57 +00:00
---
title: About the bash Resource
2018-02-16 00:28:15 +00:00
platform: linux
2016-09-22 12:43:57 +00:00
---
# bash
Use the `bash` InSpec audit resource to test an arbitrary command that is run on the system using a Bash script.
2017-10-03 21:35:10 +00:00
<br>
2016-09-27 19:03:23 +00:00
## Syntax
2016-09-22 12:43:57 +00:00
A `command` resource block declares a command to be run, one (or more) expected outputs, and the location to which that output is sent:
describe bash('command') do
it { should exist }
2018-02-01 22:44:10 +00:00
its('property') { should eq 'expected value' }
2016-09-22 12:43:57 +00:00
end
where
* `'command'` must specify a command to be run
2018-02-01 22:44:10 +00:00
* `'property'` is one of `exit_status`, `stderr`, or `stdout`
* `'expected value'` tests the output of the command run on the system versus the expected output stated in the test
2016-09-22 12:43:57 +00:00
For example:
describe bash('ls -al /') do
its('stdout') { should match /bin/ }
its('stderr') { should eq '' }
its('exit_status') { should eq 0 }
end
2017-10-03 21:35:10 +00:00
<br>
2016-09-22 12:43:57 +00:00
2018-02-15 14:33:22 +00:00
## Properties
2016-09-22 12:43:57 +00:00
2018-02-01 22:44:10 +00:00
* `exit_status`, `stderr`, `stdout`
2016-09-22 12:43:57 +00:00
2018-02-01 22:44:10 +00:00
<br>
2016-09-22 12:43:57 +00:00
2018-02-01 22:44:10 +00:00
## Property Examples
2016-09-22 12:43:57 +00:00
2016-09-27 19:03:23 +00:00
### exit_status
2016-09-22 12:43:57 +00:00
2018-02-01 22:44:10 +00:00
The `exit_status` property tests the exit status for the command:
2016-09-22 12:43:57 +00:00
its('exit_status') { should eq 0 }
2016-09-27 19:03:23 +00:00
### stderr
2016-09-22 12:43:57 +00:00
2018-02-01 22:44:10 +00:00
The `stderr` property tests results of the command as returned in standard error (stderr):
2016-09-22 12:43:57 +00:00
its('stderr') { should eq '' }
2016-09-27 19:03:23 +00:00
### stdout
2016-09-22 12:43:57 +00:00
2018-02-01 22:44:10 +00:00
The `stdout` property tests results of the command as returned in standard output (stdout).
2016-09-22 12:43:57 +00:00
its('stdout') { should match /bin/ }
2018-02-01 22:44:10 +00:00
<br>
## Matchers
2018-02-16 03:07:18 +00:00
For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
2018-02-01 22:44:10 +00:00
### exist
If an absolute path is provided, the `exist` matcher tests if the command exists on the filesystem at the specified location. Otherwise, the `exist` matcher tests if the command is found in the PATH.
it { should exist }