Search code examples
shellunixscriptingcsh

C Shell: How to execute a program with non-command line arguments?


My $SHELL is tcsh. I want to run a C shell script that will call a program many times with some arguments changed each time. The program I need to call is in Fortran. I do not want to edit it. The program only takes arguments once it is executed, but not on the command line. Upon calling the program in the script, the program takes control (this is where I am stuck currently, I can never get out because the script will not execute anything until after the program process stops). At this point I need to pass it some variables, then after several iterations I will need to Ctrl+C out of the program and continue with the script.

How can this be done?


Solution

  • To add to what @Toybuilder said, you can use a "here document". I.e. your script could have

    ./myfortranprogram << EOF
    first line of input
    second line of input
    EOF
    

    Everything between the "<<EOF" and the "EOF" will be fed to the program's standard input (does Fortran still use "read (5,*)" to read from standard input?)

    And because I think @ephemient's comment deserves to be in the answer:

    Some more tips: <<'EOF' prevents interpolation in the here-doc body; <<-EOF removes all leading tabs (so you can indent the here-doc to match its surroundings), and EOF can be replaced by any token. An empty token (<<"") indicates a here-doc that stops at the first empty line.

    I'm not sure how portable those ones are, or if they're just tcsh extensions - I've only used the <<EOF type "here document" myself.