I am trying to write a bash script to pass a user input string into a Matlab function.
This is the script I currently have:
#!/bin/bash
echo Input a message.
read message
matlab -r -nosplash -nodesktop -nojvm "arduinoWriter\(\'$message\'\);"
where arduinoWriter is a Matlab function that takes a string as an input.
If I run the script and input HELLO , it works as expected. If however I input HELLO WORLD, it does not work. Something about the space is messing it up.
If I run the command matlab -r -nosplash -nodesktop -nojvm "arduinoWriter\(\HELLO\ WORLD\'\);" in the terminal, it works fine, but not if I use HELLO\ WORLD as in the input to the bash script. Even if it did work as an input, I would prefer not to have to put slashes in front of every space.
Any ideas?
inputwithin MATLAB, or write an M-file script that you execute withmatlab -r.