From 9c0fc4ba8d0235be2a60b9a877c7f566ae1720a5 Mon Sep 17 00:00:00 2001
From: sjplimp
shell cmd args-
cd arg = dir dir = directory to change to @@ -28,6 +28,8 @@ file1,file2 = one or more filenames to delete rmdir args = dir1 dir2 ... dir1,dir2 = one or more directories to delete + putenv args = var1=value1 var2=value2 + var=value = one of more definitions of environment variables anything else is passed as a command to the shell for direct execution@@ -40,6 +42,7 @@ shell mkdir tmp1 tmp2 tmp3 shell rmdir tmp1 shell mv log.lammps hold/log.1 shell rm TMP/file1 TMP/file2 +shell putenv LAMMPS_POTENTIALS=../../potentials shell my_setup file1 10 file2 shell my_post_process 100 dump.out @@ -77,6 +80,12 @@ files. more directories. A directory must be empty to be successfully removed. +
The putenv 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, only the usual substitution for +LAMMPS variables defined with the variable command is +performed. The resulting string is then 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/doc/shell.txt b/doc/shell.txt index 1369df80a9..205164f874 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 {putenv} or arbitrary command :ulb,l {cd} arg = dir dir = directory to change to {mkdir} args = dir1 dir2 ... @@ -24,6 +24,8 @@ 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 + {putenv} args = var1=value1 var2=value2 + var=value = one of more definitions of environment variables anything else is passed as a command to the shell for direct execution :pre :ule @@ -35,6 +37,7 @@ shell mkdir tmp1 tmp2 tmp3 shell rmdir tmp1 shell mv log.lammps hold/log.1 shell rm TMP/file1 TMP/file2 +shell putenv LAMMPS_POTENTIALS=../../potentials shell my_setup file1 10 file2 shell my_post_process 100 dump.out :pre @@ -72,6 +75,12 @@ The {rmdir} cmd executes the Unix "rmdir" command to remove one or more directories. A directory must be empty to be successfully removed. +The {putenv} 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, only the usual substitution for +LAMMPS variables defined with the "variable"_variable.html command is +performed. The resulting string is then 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/doc/variable.html b/doc/variable.html index 8ab277568c..1e11913bc3 100644 --- a/doc/variable.html +++ b/doc/variable.html @@ -17,7 +17,7 @@
delete = no args index args = one or more strings @@ -39,6 +39,7 @@ N = integer size of loop pad = all values will be same length, e.g. 001, 002, ..., 100 string arg = one string + getenv arg = one string file arg = filename atomfile arg = filename equal or atom args = one formula containing numbers, thermo keywords, math operations, group functions, atom values and vectors, compute/fix/variable references @@ -139,11 +140,11 @@ means that using the command-line switch< script.There are two exceptions to this rule. First, variables of style -string and equal and atom ARE redefined each time the command is -encountered. This allows these style of variables to be redefined -multiple times in an input script. In a loop, this means the formula -associated with an equal or atom style variable can change if it -contains a substitution for another variable, e.g. $x. +string, getenv, equal and atom ARE redefined each time the +command is encountered. This allows these style of variables to be +redefined multiple times in an input script. In a loop, this means +the formula associated with an equal or atom style variable can +change if it contains a substitution for another variable, e.g. $x.
Second, as described below, if a variable is iterated on to the end of its list of strings via the next command, it is removed @@ -246,6 +247,16 @@ single string is that a variable with string style can be redefined. E.g. by another command later in the input script, or if the script is read again in a loop.
+For the getenv style, a single string is assigned to the variable +which should be the name of an environment variable. When the +variable is evaluated, it returns the value of the environment +variable, or an empty string if it not defined. This style of +variable can be used to adapt the behavior of LAMMPS input scripts via +environment variable settings, or to retrieve information that has +been previously stored with the shell putenv command. +Note that because environment variable settings are stored by the +operating systems, they persist beyond a clear command. +
For the file style, a filename is provided which contains a list of strings to assign to the variable, one per line. The strings can be numeric values if desired. See the discussion of the next() function diff --git a/doc/variable.txt b/doc/variable.txt index b81c9c84de..ad11cc0b27 100644 --- a/doc/variable.txt +++ b/doc/variable.txt @@ -13,7 +13,7 @@ variable command :h3 variable name style args ... :pre name = name of variable to define :ulb,l -style = {delete} or {index} or {loop} or {world} or {universe} or {uloop} or {string} or {file} or {atomfile} or {equal} or {atom} :l +style = {delete} or {index} or {loop} or {world} or {universe} or {uloop} or {string} or {getenv} or {file} or {atomfile} or {equal} or {atom} :l {delete} = no args {index} args = one or more strings {loop} args = N @@ -34,6 +34,7 @@ style = {delete} or {index} or {loop} or {world} or {universe} or {uloop} or {st N = integer size of loop pad = all values will be same length, e.g. 001, 002, ..., 100 {string} arg = one string + {getenv} arg = one string {file} arg = filename {atomfile} arg = filename {equal} or {atom} args = one formula containing numbers, thermo keywords, math operations, group functions, atom values and vectors, compute/fix/variable references @@ -133,11 +134,11 @@ means that using the "command-line switch"_Section_start.html#start_7 script. There are two exceptions to this rule. First, variables of style -{string} and {equal} and {atom} ARE redefined each time the command is -encountered. This allows these style of variables to be redefined -multiple times in an input script. In a loop, this means the formula -associated with an {equal} or {atom} style variable can change if it -contains a substitution for another variable, e.g. $x. +{string}, {getenv}, {equal} and {atom} ARE redefined each time the +command is encountered. This allows these style of variables to be +redefined multiple times in an input script. In a loop, this means +the formula associated with an {equal} or {atom} style variable can +change if it contains a substitution for another variable, e.g. $x. Second, as described below, if a variable is iterated on to the end of its list of strings via the "next"_next.html command, it is removed @@ -240,6 +241,16 @@ single string is that a variable with {string} style can be redefined. E.g. by another command later in the input script, or if the script is read again in a loop. +For the {getenv} style, a single string is assigned to the variable +which should be the name of an environment variable. When the +variable is evaluated, it returns the value of the environment +variable, or an empty string if it not defined. This style of +variable can be used to adapt the behavior of LAMMPS input scripts via +environment variable settings, or to retrieve information that has +been previously stored with the "shell putenv"_shell.html command. +Note that because environment variable settings are stored by the +operating systems, they persist beyond a "clear"_clear.html command. + For the {file} style, a filename is provided which contains a list of strings to assign to the variable, one per line. The strings can be numeric values if desired. See the discussion of the next() function