From 087056c03fd1584e648ab8d47093ca019aae58aa Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 5 Oct 2013 19:44:12 +0200 Subject: [PATCH] add a shell setenv command --- doc/shell.txt | 10 +++++++++- src/input.cpp | 14 +++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/doc/shell.txt b/doc/shell.txt index 1369df80a9..793a9fc8de 100644 --- a/doc/shell.txt +++ b/doc/shell.txt @@ -12,7 +12,7 @@ shell command :h3 shell cmd args :pre -cmd = {cd} or {mkdir} or {mv} or {rm} or {rmdir} or arbitrary command :ulb,l +cmd = {cd} or {mkdir} or {mv} or {rm} or {rmdir} or {setenv} or arbitrary command :ulb,l {cd} arg = dir dir = directory to change to {mkdir} args = dir1 dir2 ... @@ -24,6 +24,9 @@ cmd = {cd} or {mkdir} or {mv} or {rm} or {rmdir} or arbitrary command :ulb,l file1,file2 = one or more filenames to delete {rmdir} args = dir1 dir2 ... dir1,dir2 = one or more directories to delete + {setenv} args = name value + name = name of the environment variable + value = value of the environment variable anything else is passed as a command to the shell for direct execution :pre :ule @@ -35,6 +38,7 @@ shell mkdir tmp1 tmp2 tmp3 shell rmdir tmp1 shell mv log.lammps hold/log.1 shell rm TMP/file1 TMP/file2 +shell setenv LAMMPS_POTENTIALS ../../potentials shell my_setup file1 10 file2 shell my_post_process 100 dump.out :pre @@ -72,6 +76,10 @@ The {rmdir} cmd executes the Unix "rmdir" command to remove one or more directories. A directory must be empty to be successfully removed. +The {setenv} cmd defines or updates an environment variable directly. +Since this command does not pass through the shell, no shell variable +expansion or globbing is performed, but the value string used literally. + Any other cmd is passed as-is to the shell along with its arguments as one string, invoked by the C-library system() call. For example, these lines in your input script: diff --git a/src/input.cpp b/src/input.cpp index 24b2016a26..1e40d1e4f4 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -980,11 +980,11 @@ void Input::shell() if (narg < 1) error->all(FLERR,"Illegal shell command"); if (strcmp(arg[0],"cd") == 0) { - if (narg != 2) error->all(FLERR,"Illegal shell command"); + if (narg != 2) error->all(FLERR,"Illegal shell cd command"); chdir(arg[1]); } else if (strcmp(arg[0],"mkdir") == 0) { - if (narg < 2) error->all(FLERR,"Illegal shell command"); + if (narg < 2) error->all(FLERR,"Illegal shell mkdir command"); #if !defined(WINDOWS) && !defined(__MINGW32__) if (me == 0) for (int i = 1; i < narg; i++) @@ -992,19 +992,23 @@ void Input::shell() #endif } else if (strcmp(arg[0],"mv") == 0) { - if (narg != 3) error->all(FLERR,"Illegal shell command"); + if (narg != 3) error->all(FLERR,"Illegal shell mv command"); if (me == 0) rename(arg[1],arg[2]); } else if (strcmp(arg[0],"rm") == 0) { - if (narg < 2) error->all(FLERR,"Illegal shell command"); + if (narg < 2) error->all(FLERR,"Illegal shell rm command"); if (me == 0) for (int i = 1; i < narg; i++) unlink(arg[i]); } else if (strcmp(arg[0],"rmdir") == 0) { - if (narg < 2) error->all(FLERR,"Illegal shell command"); + if (narg < 2) error->all(FLERR,"Illegal shell rmdir command"); if (me == 0) for (int i = 1; i < narg; i++) rmdir(arg[i]); + } else if (strcmp(arg[0],"setenv") == 0) { + if (narg != 3) error->all(FLERR,"Illegal shell setenv command"); + setenv(arg[1],arg[2],1); + // use work string to concat args back into one string separated by spaces // invoke string in shell via system()