Menu

#287 make script file name available to script code

None
closed
nobody
None
5
2023-12-01
2023-10-11
No

Hello all,

I heavily rely on scripts to display data.

My setup is that I have "01.txt" as data file and "01 plot.gp" as script file, etc.

My question: is there a command / way to refer to the name of the script inside the script (the equivalent of bash's $0)? My goal is to derive the name of the data file from the name of the script file in order to plot it.

Thanks.
Daniel

Discussion

  • Hiroki Motoyoshi

    Have you tried looking at variable ARG0?

    test.gp:

    show variables ARG
    
    print "Script name is " . ARG0
    

    This script produces output like

        Variables beginning with ARG:
        ARGC = 0
        ARG0 = "test.gp"
        ARGV = <0 element array>
        ARG1 = ""
        ARG2 = ""
        ARG3 = ""
        ARG4 = ""
        ARG5 = ""
        ARG6 = ""
        ARG7 = ""
        ARG8 = ""
        ARG9 = ""
    
    Script name is test.gp
    

    My environment is gnuplot 5.4.8 installed via Macports on MacOS.

     
    👍
    1

    Last edit: Hiroki Motoyoshi 2023-10-11
  • Daniel Dan K.

    Daniel Dan K. - 2023-10-12

    Thanks a lot. That's helpful.

     
  • Daniel Dan K.

    Daniel Dan K. - 2023-10-12

    If anybody is interested: this is my way to extract the script name from ARG0:

    start=1; while(1) { pos=strstrt(ARG0[start:], '\') ; if(pos==0) {break;}; start=start+pos; }; scriptname=ARG0[start:]
    
    print "script name='".scriptname."'"
    

    works on Windows.

     
  • Daniel Dan K.

    Daniel Dan K. - 2023-12-01

    This support ticket can be closed. I don't know how to do this.

     
  • Ethan Merritt

    Ethan Merritt - 2023-12-01
    • status: open --> closed
    • Group: -->
     

Log in to post a comment.