Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Help with UNIX() command

Subject: Help with UNIX() command

From: John

Date: 4 Apr, 2013 19:26:05

Message: 1 of 6

I want to run a shell script within MATLAB, but the script is csh. When I try running it in MATLAB it says /bin/bash commande does not exist. How do I get MATLAB to run the UNIX command using csh and not bash?

Subject: Help with UNIX() command

From: Nasser M. Abbasi

Date: 4 Apr, 2013 19:43:23

Message: 2 of 6

On 4/4/2013 2:26 PM, John wrote:
> I want to run a shell script within MATLAB, but the script is csh. When I try running
>it in MATLAB it says /bin/bash commande does not exist. How do I get MATLAB
>to run the UNIX command using csh and not bash?
>

When you explain a problem, it helps to also show what you actually
typed. No one can see your screen from here to figure what you
typed.

But may be this helps

http://www.mathworks.com/help/matlab/ref/system.html

"system

Execute operating system command and return output"

Subject: Help with UNIX() command

From: John

Date: 4 Apr, 2013 19:52:05

Message: 3 of 6

"Nasser M. Abbasi" wrote in message <kjkl4o$if2$1@speranza.aioe.org>...
> On 4/4/2013 2:26 PM, John wrote:
> > I want to run a shell script within MATLAB, but the script is csh. When I try running
> >it in MATLAB it says /bin/bash commande does not exist. How do I get MATLAB
> >to run the UNIX command using csh and not bash?
> >
>
> When you explain a problem, it helps to also show what you actually
> typed. No one can see your screen from here to figure what you
> typed.
>
> But may be this helps
>
> http://www.mathworks.com/help/matlab/ref/system.html
>
> "system
>
> Execute operating system command and return output"

[s,w]=unix('to3d -session e126 -prefx 4244_run_01 -epan -time:zt 28 104 1800 altplus ./s1037/*MRDC*')
/bin/bash: to3d: command not found

That is what I run and the error I get. Using system produces the same error. The problem is MATLAB is trying to run it through a bash shell, and its a command for a c-shell(csh). I need to know how to get MATLAB to execute the command in a c-shell. and ! will not work either for the exact same reason.

Subject: Help with UNIX() command

From: Nasser M. Abbasi

Date: 4 Apr, 2013 20:32:29

Message: 4 of 6

On 4/4/2013 2:52 PM, John wrote:

>>
>> But may be this helps
>>
>> http://www.mathworks.com/help/matlab/ref/system.html
>>
>> "system
>>
>> Execute operating system command and return output"

>
> [s,w]=unix('to3d -session e126 -prefx 4244_run_01 -epan -time:zt 28 104 1800 altplus ./s1037/*MRDC*')
> /bin/bash: to3d: command not found
>
> That is what I run and the error I get. Using system produces the same error.
>The problem is MATLAB is trying to run it through a bash shell, and its a
>command for a c-shell(csh). I need to know how to get MATLAB to execute
>the command in a c-shell. and ! will not work either for the exact same reason.
>

Matlab is not trying to do anything. Matlab knows nothing about c-shells
or bash or sh or DOS or anything of this stuff.

I am sure all what it does is an exec() somewhere and hands the new process created the
command you issued to run.

http://linux.die.net/man/3/exec
"The initial argument for these functions is the name of a file that is to be executed"

So you need to look at your own login process to see what default shell
gets invoked for it. Basically, if you can login to Linux and
type the above command from the terminal and it works, then you should be able to
do the same from Matlab using the system("command")

It looks like your linux login sets bash as the default shell, and the
PATH is not setup to find c-shell, or c-shell it not installed.

You have to look at the command itself first, make sure it works OK on
its own.

--Nasser

Subject: Help with UNIX() command

From: Steven_Lord

Date: 5 Apr, 2013 14:53:49

Message: 5 of 6



"John " <atreides1234@gmail.com> wrote in message
news:kjkll5$j6o$1@newscl01ah.mathworks.com...
> "Nasser M. Abbasi" wrote in message <kjkl4o$if2$1@speranza.aioe.org>...
>> On 4/4/2013 2:26 PM, John wrote:
>> > I want to run a shell script within MATLAB, but the script is csh.
>> > When I try running
>> >it in MATLAB it says /bin/bash commande does not exist. How do I get
>> >MATLAB
>> >to run the UNIX command using csh and not bash?
>> >
>>
>> When you explain a problem, it helps to also show what you actually
>> typed. No one can see your screen from here to figure what you
>> typed.
>>
>> But may be this helps
>>
>> http://www.mathworks.com/help/matlab/ref/system.html
>>
>> "system
>>
>> Execute operating system command and return output"
>
> [s,w]=unix('to3d -session e126 -prefx 4244_run_01 -epan -time:zt 28 104
> 1800 altplus ./s1037/*MRDC*')
> /bin/bash: to3d: command not found
>
> That is what I run and the error I get. Using system produces the same
> error. The problem is MATLAB is trying to run it through a bash shell,
> and its a command for a c-shell(csh).

Are you certain that's the problem?

Where is this to3d command located? If it is in your current directory, try:

[s,w]=unix('./to3d -session e126 -prefx 4244_run_01 -epan -time:zt 28 104
1800 altplus ./s1037/*MRDC*')

If it's somewhere else, you will need to either use the path to that
location in your UNIX command or you will need to ensure that location is on
the _system_ path (it doesn't matter whether or not it is on the MATLAB
path.)

> I need to know how to get MATLAB to execute the command in a c-shell. and
> ! will not work either for the exact same reason.

Before we go blaming the shell without hard-and-fast proof, quickly check
for other causes that provoke the same symptoms.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Help with UNIX() command

From: Doug Schwarz

Date: 6 Apr, 2013 02:43:33

Message: 6 of 6

In article <kjkll5$j6o$1@newscl01ah.mathworks.com>,
 "John " <atreides1234@gmail.com> wrote:

> "Nasser M. Abbasi" wrote in message <kjkl4o$if2$1@speranza.aioe.org>...
> > On 4/4/2013 2:26 PM, John wrote:
> > > I want to run a shell script within MATLAB, but the script is csh. When
> > > I try running
> > >it in MATLAB it says /bin/bash commande does not exist. How do I get
> > >MATLAB
> > >to run the UNIX command using csh and not bash?
> > >
> >
> > When you explain a problem, it helps to also show what you actually
> > typed. No one can see your screen from here to figure what you
> > typed.
> >
> > But may be this helps
> >
> > http://www.mathworks.com/help/matlab/ref/system.html
> >
> > "system
> >
> > Execute operating system command and return output"
>
> [s,w]=unix('to3d -session e126 -prefx 4244_run_01 -epan -time:zt 28 104 1800
> altplus ./s1037/*MRDC*')
> /bin/bash: to3d: command not found
>
> That is what I run and the error I get. Using system produces the same
> error. The problem is MATLAB is trying to run it through a bash shell, and
> its a command for a c-shell(csh). I need to know how to get MATLAB to
> execute the command in a c-shell. and ! will not work either for the exact
> same reason.

If you really want to execute the command in a c-shell, try

[s,w]=unix('csh -c "to3d -session e126 -prefx 4244_run_01 -epan -time:zt
28 104 1800 altplus ./s1037/*MRDC*"')

but it really just looks like the command t03d isn't on your path (the
posix one). Figure out where that command lives by typing

which to3d

in a shell terminal. Let's say it's in /usr/local/bin. You can add
that directory to the posix path from within MATLAB with something like

current_path = getenv('PATH');
new_path = [current_path,pathsep,'/usr/local/bin'];
setenv('PATH',new_path)

which you can put in your startup m-file.

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us