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.
Examples
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
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
Output of the operating system command, returned as a character vector. The system shell might not properly represent non-Unicode® characters.
Extended Capabilities
Usage notes and limitations:
stdin
of the calling process is inherited on Windows® and UNIX.- On UNIX, if a second output is requested,
stdout
is redirected to a pipe. Otherwise,stdout
is inherited from the calling process. - On Windows, the
nargout
determines whether the output read from the pipe is stored in a variable or sent tostdout
of the calling process. If the number of arguments is 1, the output from the pipe is sent tostdout
. Otherwise, it is stored in a variable.
Version History
Introduced before R2006a