Skip to Main Content Skip to Search
Product Documentation

unix - Execute UNIX command and return 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. The command executes in a UNIX shell, which might not be the shell from which you launched MATLAB.

status = unix('command') returns completion status to the status variable.

[status, result] = unix('command') returns the standard output to the result variable.

[status,result] = unix('command','-echo') displays the results in the Command Window as it executes, and assigns the results to result.

This function is interchangeable with the system and dos functions. They all have the same effect.

Examples

List all users that are currently logged in.

[s,w] = unix('who');

MATLAB returns 0 (success) in s and a string containing the list of users in w.

 

Execute a string, why, that is not a UNIX command.

[s,w] = unix('why')
s =
    1
w =
why: Command not found.

MATLAB returns a nonzero value in s to indicate failure, and returns an error message in w.

Algorithms

The MATLAB software 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. If SHELL is also empty or not defined, MATLAB uses /bin/sh.

See Also

! (exclamation point) | computer | dos | perl | system

How To

  


» Learn more
» Download free kit
» Get trial software

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS