Debian Codegraph @

docs/ug/user_manual/text_based_suite_definition/attributes/edit_add_variable.rst

raw
1 .. _edit_add_variable:
2
3 variable
4 ////////
5
6 This defines a variable for ecFlow job substitution in a node, equivalent to an external variable.
7 There can be any number of variables defined at any node level: suite, family or task.
8
9 The textual definition of a variable is as follows, where :code:`<name>` is the name of the variable and
10 :code:`<value>` is the value of the variable. Variable names are case sensitive.
11
12 After the variable name and value, an optional comment can be provided. The comment must be preceded by
13 a :code:`#` character, after the variable value. The comment is ignored, and serves only as a note for
14 users reading the suite definition.
15
16 .. code-block:: shell
17
18 edit <name> <value>
19 edit <name> <value> # optional comment
20 edit <name> '<value with spaces>'
21 edit <name> "<value with spaces>" # optional comment
22
23 .. important::
24
25 **Use single quotes to delimit the value of a variable.**
26
27 Although not mandatory, it is a highly recommended practice to *always* use single quotes to enclose
28 the value of a variable, even if it does not contain spaces. This avoids any misinterpretation of special
29 characters, including whitespace, in the value and ensures that the variable value is treated as a single entity.
30
31 .. hint::
32
33 Define each variable on a separate line, and avoid defining multiple variables on the same line.
34 This enhances readability and maintainability of the suite definition.
35
36 To use the variable in an ecFlow task script refer to it by its name, inside a pair of :code:`%` (:code:`ECF_MICRO`)
37 characters e.g. :code:`VARIABLE`, taking care to exactly match the case of the variable name.
38 The replacement of the variable name, surrounded by :code:`ECF_MICRO`, by the value of the variable is performed
39 during the job script rendering at submission time.
40
41 .. code-block:: shell
42
43 edit ECF_JOB_CMD '/bin/sh %ECF_JOB% &'
44 edit ECF_JOB_CMD '/usr/local/bin/qsub %ECF_JOB%'
45 edit ECF_JOB_CMD 'rsh %ECF_HOST% sh <%ECF_JOB% 1>%ECF_JOBOUT% 2>&1'
46 edit KEEPLOGS no
47
48 When defining a variable value, care is needed to ensure that the value is correctly interpreted.
49
50 * An unquoted variable value is determined by the first whitespace character after the variable name,
51 and the comment character :code:`#` is expected to appear after the value when an optional
52 comment is provided. If more content appears after the unquoted value before the presence of a
53 comment character :code:`#` the variable definition is considered invalid.
54
55 * If a quote is used, determined by the presence of either :code:`'` or :code:`"` after the variable name,
56 the variable value includes all the content between the first and last occurrence of the quotation marker
57 in the line, potentially making the comment character :code:`#` part of the variable value if it appears
58 within the quotes.
59
60 The following examples present invalid variable definitions:
61
62 .. code-block:: shell
63
64 edit SCRIPT /bin/sh script.sh &
65
66 Since the value above is unquoted, the variable value is interpreted as simply `/bin/sh`
67 and the expected comment marked `#` is missing after the value.
68
69 .. code-block:: shell
70
71 edit SCRIPT '/bin/sh script.sh &' # it's a comment
72
73 Since the value above is single quoted, determined by the opening single quote of the value,
74 the value is interpreted as `/bin/sh script.sh &' # it` (delimited by the last `'` that
75 appears in the entire line) and the expected comment marked `#` is missing after the value.
76
77 Server variables
78 ----------------
79
80 Variables defined at the top level can either be considered user or server variables.
81 The definition of server variables is reserved for ecFlow administrators, and are
82 relevant only in the context of checkpoint files.
83
84 .. warning::
85
86 Server variables should not be used by users defining their own suites.
87
88 In checkpoint files, Server variables are identified by the presence of the comment
89 :code:`# server` after the variable value, as shown in the example below.
90
91 .. code-block:: shell
92
93 edit ECF_HOME '/home/ecflow' # server
94 edit ECF_PORT '3141' # server
95 edit ECF_HOST 'ecflow-hostname' # server