unix

Runs a command through the Unix shell and returns its status and output.

Category: Environment and Settings > System Commands

Syntax

status = unix(cmd)

Runs cmd, showing its output, and returns the exit status.

[status, out] = unix(cmd)

Captures the output in out instead of showing it.

Description

unix is the Unix-specific counterpart of dos: it behaves like system, intended for Linux and macOS shells. Code that must run on every platform should call system instead.

Input arguments

cmd
Command line to run.

Output arguments

status
Exit code of the command; 0 means success.
out
Text the command wrote as output.

Example

Capture the output

[status, out] = unix('echo hi');
disp(status)
disp(strtrim(out))
Output
     0
hi

Notes

MatLivre runs the command on any host, including Windows. In MATLAB for Windows, unix is not meant to be used.

See also

system dos perl cmdsep