unix - Execute UNIX command and return output - MATLAB (original) (raw)

Main Content

Execute UNIX command and return output

For platform-independent code, use the system command.

Syntax

Description

[[status](#btoe4z0-1%5Fsep%5Fshared-status),[cmdout](#btoe4z0-1%5Fsep%5Fshared-cmdout)] = unix([command](#btoe4z0-1-command)) calls the operating system to execute the specified command and returns the standard output of the command to cmdout.

MATLAB® uses a shell program to execute the given command. It determines which shell program to use by checking environment variables on your system. MATLAB first checks the MATLAB_SHELL variable, and if either empty or not defined, then checks SHELL. IfSHELL is also empty or not defined, MATLAB uses /bin/sh.

For tips and information about limitations, see system.

example

Examples

collapse all

Display the current folder using the cd command. Astatus of zero indicates that the command completed successfully. MATLAB returns a character vector containing the current folder incmdout.

command = 'cd'; [status,cmdout] = unix(command)

Input Arguments

collapse all

UNIX command, specified as a character vector. The command executes in a UNIX shell, which might not be the shell from which you started MATLAB.

Example: 'ls'

Output Arguments

collapse all

Output of the operating system command, returned as a character vector. The system shell might not properly represent non-Unicode® characters.

Extended Capabilities

expand all

Usage notes and limitations:

Version History

Introduced before R2006a