|
From: Ethan M. <eam...@gm...> - 2020-06-24 05:04:53
|
On Tuesday, 23 June 2020 14:26:41 PDT Jon wrote:
> Hi,
>
> I am trying to execute a script ssss.gn within gnuplot 5.2.2 in
> linuxmint 18.2 including the following lines
> pwdd="`pwd`"
> do for [ dir in "4.1 4.15 4.2 4.25 4.3 "] {
> print dir
> cd dir."/right/here/waiting/"
> ef=`head -n 1 DOSCAR | awk '{print $5}'`
> print ef
> cd pwdd
> }
>
> but it complains
I do not fully understand this myself, but I do know how avoid the problem.
There is a subtle difference between
foo = "`some command`"
and
foo = system("some command")
in that the back-quote version is evaluated during command parsing,
while the system() command is evaluated during execution.
I am not sure why exactly that matters in your case but apparently it does.
You can fix it by replacing the back-quotes with a system command
pwdd = system("pwd")
do for [ dir in "4.1 4.15 4.2 4.25 4.3 "] {
print dir
cd dir."/right/here/waiting/"
ef = system("head -n 1 DOSCAR | awk '{print $5}'")
print ef
cd pwdd
}
> gnuplot> load "ssss.gn"
> head: cannot open 'DOSCAR' for reading: No such file or directory
> 4.1
> line 5: constant expression required
>
> but the file does exist under the directory, why would it complain
> file not existing
>
> Another confusing observation is the error concerning nonexistence of
> DOSCAR comes before the print statement in the script. Why is that?
It is a symptom of the back-quote evaluation occuring during an
earlier stage of processing than the loop execution.
Ethan
>
> Thanks,
>
> Sincerely,
> Jon
|