Re: Problem in bash script with single and double quotes
- From: Janis Papanagnou <Janis_Papanagnou@xxxxxxxxxxx>
- Date: Thu, 10 Jul 2008 23:04:19 +0200
kittythebulldog-1@xxxxxxxxx wrote:
I have an application program called matlab that I run from an
interactive bash shell by using the command
matlab -r "load('a.mat');sum(a)"
The single and double quotes must be present as shown.
Now I would like to run the exact same line from within a bash script,
with the only difference being that the file name a.mat should be
stored in a variable. The script I wrote is:
#!/bin/bash -
l
set -x # display each
line
# interactive line that
works
# matlab -r
"load('a.mat');sum(a)"
F=a.mat
line='matlab -r "load('\'${F}\'');sum(a)"'
In your script just call it as...
matlab -r "load('${F}');sum(a)"
The variable expansion ${F} will be effective because the whole
expression is inside double quotes.
(And fix the linebreaks before you post again.)
Janis
.
# the echoed line is
correct
echo $line
# neither of the next two lines
works
${line}
#exec $
{line}
When I run the script the output (from having set -x) is
+ source demo.sh
++ set -x
++ F=a.mat
++ line='matlab -r "load('\''a.mat'\'');sum(a)"'
++ echo matlab -r '"load('\''a.mat'\'');sum(a)"'
matlab -r "load('a.mat');sum(a)"
++ matlab -r '"load('\''a.mat'\'');sum(a)"'
The second to last line shows the value of the variable containing the
command that I want to run. This line comes from echo is exactly what
I want. However, the last line shows that when I try to run the line
contained in the variable not all the characters in the variable are
translated, as they are by echo, and matlab doesn't run correctly.
What can I do to run the program, i.e., so that the last line is the
same as the second to last line?
Thanks.
Greg Reese
- References:
- Problem in bash script with single and double quotes
- From: kittythebulldog-1
- Problem in bash script with single and double quotes
- Prev by Date: Problem in bash script with single and double quotes
- Next by Date: Re: How to find all files between midnight and 08.00 am?
- Previous by thread: Problem in bash script with single and double quotes
- Next by thread: Re: Problem in bash script with single and double quotes
- Index(es):
Relevant Pages
|
Loading