Execute Bash script using Cygwin

  • Follow


Hello, I am trying to execute a bash script in Windows through the 'unix' command via Cygwin. Basically, with Cygwin installed, I can use the 'unix' command to execute unix commands (grep, find etc.). However, when I try to execute a shell script with the unix command, matlab OPENS the shell script instead of executing it. So basically 
unix('MyShell.sh')
will open MyShell.sh in a text editor, instead of executing it. Any ideas? I have both the Matlab and Windows environment path variables pointing to the directory MyShell.sh is in. 

Thanks a lot!
0
Reply Andres 3/22/2011 10:02:04 AM


"Andres " <ablackone@gmail.com> wrote in message 
news:im9s2s$8f3$1@fred.mathworks.com...
> Hello, I am trying to execute a bash script in Windows through the 'unix' 
> command via Cygwin. Basically, with Cygwin installed, I can use the 'unix' 
> command to execute unix commands (grep, find etc.). However, when I try to 
> execute a shell script with the unix command, matlab OPENS the shell 
> script instead of executing it. So basically unix('MyShell.sh')
> will open MyShell.sh in a text editor, instead of executing it. Any ideas? 
> I have both the Matlab and Windows environment path variables pointing to 
> the directory MyShell.sh is in.

What is the Windows file association for the extension .sh? What is the 
default action that Windows will take?

Just because you're calling the UNIX command doesn't mean that MATLAB will 
execute the command "as though" this was a UNIX machine; it simply hands the 
command to the OS and says "Here, you execute this."

http://www.mathworks.com/help/techdoc/ref/unix.html

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

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

0
Reply Steven_Lord 3/22/2011 1:34:17 PM


Hi Steve, thanks for the input. Windows default action is just to open the file in a text editor, now that I know better how everything works I guess it all makes sense. 

I managed to find a workaround for executing the script using Cygwin from Matlab. Say the script is "MyScript.sh". It executes with 

system('C:\cygwin\bin\bash --login -c "MyScript.sh"');

Thanks!
0
Reply Andres 3/22/2011 2:12:04 PM

"Andres " <ablackone@gmail.com> wrote in message <imaank$ilu$1@fred.mathworks.com>...
> Hi Steve, thanks for the input. Windows default action is just to open the file in a text editor, now that I know better how everything works I guess it all makes sense. 
> 
> I managed to find a workaround for executing the script using Cygwin from Matlab. Say the script is "MyScript.sh". It executes with 
> 
> system('C:\cygwin\bin\bash --login -c "MyScript.sh"');
> 
> Thanks!

Hello,

That is exactly what i need! However, how could you specify the path of the file "MyScript.sh"?

Thanks!
0
Reply seb6232 (5) 8/22/2011 2:23:10 PM

3 Replies
433 Views

(page loaded in 0.107 seconds)

Similiar Articles:













7/23/2012 8:43:40 AM


Reply: