Is it possible to check if file exist and use that to set a variable value to 0 or 1?
Can it be done by using the shell command? but how to get an output from it either True or False?
I know i can do that by using bash and check if file exist and then change the value using -var name value via command in-line.
You can try
shell echo "0" > file_exists shell [ -f MY_FILE_NAME ] && echo "1" > file_exists variable file_exists file file_exists
Please have a closer look at the documentation for the variable command.
Here is a quote:
The is_file(name) function is a test whether name is a (readable) file and returns 1 in this case, otherwise it returns 0. For that name is taken as a literal string and must not have any blanks in it.
Thank you, I didnt know it was possible to redirect output to a variable, that solves it and allows me to do new things.
I advise against this since input files are processed in parallel by all MPI processes and redirection can lead to race conditions, corrupted files, or time lags with updating files on parallel file systems.
I agree, I dont want to use input files. In my script I have a variable called “var_restart”, if its 0 it will start a fresh run, and if its 1 then it will use the restart binaries file to continue the runs. I wanted to check if the restart file exist then I change the value of the variable to 1 at the start of the simulation before anything else.
This works too and cleaner, I already saw this but you already mentioned it. Thank you