Automatically input "yes" on the bash file

10,592
echo yes | your-program
yes yes  | your-program
Share:
10,592

Related videos on Youtube

Rilin Shen
Author by

Rilin Shen

Updated on September 18, 2022

Comments

  • Rilin Shen
    Rilin Shen over 1 year

    Slurm is workload manager. There are two kinds of modes to run job, interactive(srun) and batch mode(sbatch).

    When using interactive mode, one needs to leave the terminal open which may lead extra burden to the remote terminal(laptop).

    However, sbatch mode just submit the bash script(*.sh) and can close the remote terminal. All the following steps are handled by the computing nodes.

    When I run the executable program, it prompts "Are all filenames correct?" and expects "yes". What I want is that the script to automatically input "yes" for this prompt when running *.sh file so that the program can continue without interaction.

    If you need any further clarification, please let me know.

    • pfnuesel
      pfnuesel over 6 years
      What are you running? Many programs have a flag for this, like -y, but if you don't tell us what program you run, we cannot help.
    • Kusalananda
      Kusalananda over 6 years
      Some programs can take the input from standard input. Try piping the output of yes yes to it... That's the yes utility executed with yes as its only argument.
    • Raman Sailopal
      Raman Sailopal over 6 years
      You may have to use an expect script
    • Rilin Shen
      Rilin Shen over 6 years
      Thanks for your kind help. I'm running FEM code and the following answer does solve my issue.
  • Rilin Shen
    Rilin Shen over 6 years
    Thanks very much, It really works. I test and find something differences between these two commands. It seems echo yes | program can end the program immediately and correctly after it was run, whereas yes yes | program cannot. Could you please give me details on this issue?