Re: failure to change directory and execute linux command

Ethan Merritt <[email protected]>
Newsgroups gmane.comp.graphics.gnuplot.user
Message-ID <6888828.t6Eb5WmhxC@stonelion>
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





_______________________________________________
gnuplot-info mailing list
[email protected]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.