MATLAB Function Reference | ![]() ![]() |
Execute a UNIX command and return the result
Syntax
unix command
status = unix('command')
[status,result] = unix('command')
[status,result] = unix('command','-echo
')
Description
unix command
calls upon the UNIX operating system to execute the given command.
status = unix('command')
returns completion status to the status
variable.
[status, result] = unix('command')
returns the standard output to the result
variable, in addition to completion status, .
[status,result] = unix('command','
forces the output to the Command Window, even though it is also being assigned into a variable.-echo
')
Examples
The following example lists all users that are currently logged in. It returns a zero (success) in s
and a string containing the list of users in w.
[s,w] = unix('who');
The next example returns a nonzero value in s
to indicate failure and returns an error message in w
because why
is not a UNIX command.
[s,w] = unix('why') s = 1 w = why: Command not found.
When including the -echo
flag, MATLAB displays the results of the command in the Command Window as it executes as well as assigning the results to the return variable, w
.
[s,w] = unix('who','-echo');
See Also
![]() | unique | unwrap | ![]() |