From 53dae09abcb79c955892f125d51dee680afd5416 Mon Sep 17 00:00:00 2001 From: "Alan T. DeKok" Date: Sat, 18 Jan 2025 15:45:25 -0500 Subject: [PATCH] update test and docs in preparation for removing '&' --- .../pages/raddb/mods-available/echo.adoc | 34 ++++++++++++++++++- raddb/mods-available/echo | 34 ++++++++++++++++++- src/tests/modules/exec/module.conf | 4 +-- 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/doc/antora/modules/reference/pages/raddb/mods-available/echo.adoc b/doc/antora/modules/reference/pages/raddb/mods-available/echo.adoc index 8e46a3ba2b..f3fc544675 100644 --- a/doc/antora/modules/reference/pages/raddb/mods-available/echo.adoc +++ b/doc/antora/modules/reference/pages/raddb/mods-available/echo.adoc @@ -58,6 +58,38 @@ arguments. Dynamic translation is done on this field, so things like the following example will work. +The example program below has a few important features +which should be noted: + + * The string for the program name uses triple quotes. + These allow the text inside of the string to contain + double-quote characters without needing to escape + them. This doesn't affect the output string, but it + does make the configuration easier to read. + + * The argument to "/bin/echo" is a double-quoted string. + That is, the attribute name, operator, and value are + passed to "echo" as one argument. If the parameters to + the "echo" command were not quoted, then they would be + passed as three separate arguments. + + * The attribute value is surrounded by single quotes. + These single quotes are inside of the single argument + to the "echo" command. + + * If instead the "echo" command was passed three separate + arguments, then the attribute value would be printed + _without_ the quotes. Because quoting an argument to + a command results in the _unquoted_ string being passed + to the command, as the argument. + +The summary of all of the above is that when printing +attributes it's usually easier to run one shell script with +no arguments. That shell script can then print the +attribute names, operators, and values. + +Any string values should also be quoted. + input_pairs:: The attributes which are placed into the @@ -115,7 +147,7 @@ thereby saving resources. ``` exec echo { wait = yes - program = "/bin/echo Filter-Id := %{User-Name}" + program = """/bin/echo "Filter-Id := '%{User-Name}'" """ input_pairs = &request output_pairs = &reply shell_escape = yes diff --git a/raddb/mods-available/echo b/raddb/mods-available/echo index 6ba4c3d6be..08ce8fe386 100644 --- a/raddb/mods-available/echo +++ b/raddb/mods-available/echo @@ -63,7 +63,39 @@ exec echo { # Dynamic translation is done on this field, so things like # the following example will work. # - program = "/bin/echo Filter-Id := %{User-Name}" + # The example program below has a few important features + # which should be noted: + # + # * The string for the program name uses triple quotes. + # These allow the text inside of the string to contain + # double-quote characters without needing to escape + # them. This doesn't affect the output string, but it + # does make the configuration easier to read. + # + # * The argument to "/bin/echo" is a double-quoted string. + # That is, the attribute name, operator, and value are + # passed to "echo" as one argument. If the parameters to + # the "echo" command were not quoted, then they would be + # passed as three separate arguments. + # + # * The attribute value is surrounded by single quotes. + # These single quotes are inside of the single argument + # to the "echo" command. + # + # * If instead the "echo" command was passed three separate + # arguments, then the attribute value would be printed + # _without_ the quotes. Because quoting an argument to + # a command results in the _unquoted_ string being passed + # to the command, as the argument. + # + # The summary of all of the above is that when printing + # attributes it's usually easier to run one shell script with + # no arguments. That shell script can then print the + # attribute names, operators, and values. + # + # Any string values should also be quoted. + # + program = """/bin/echo "Filter-Id := '%{User-Name}'" """ # # input_pairs:: The attributes which are placed into the diff --git a/src/tests/modules/exec/module.conf b/src/tests/modules/exec/module.conf index 06d17a8225..2bfbe6d844 100644 --- a/src/tests/modules/exec/module.conf +++ b/src/tests/modules/exec/module.conf @@ -17,7 +17,7 @@ exec exec_async_mod { input_pairs = &request shell_escape = yes timeout = 10 - program = "/bin/sh -c 'echo \'Called-Station-Id = welcome\''" + program = '''/bin/sh -c "echo \"Called-Station-Id = 'welcome'\" " ''' } exec exec_sync { @@ -33,7 +33,7 @@ exec exec_sync_mod { output_pairs = &control shell_escape = yes timeout = 10 - program = "/bin/sh -c 'echo \'Called-Station-Id = welcome\''" + program = '''/bin/sh -c "echo \"Called-Station-Id = 'welcome'\" " ''' } exec exec_sync_attrs { -- 2.47.3