diff --git a/NEWS b/NEWS index 8e183219db..ea6ca636bd 100644 --- a/NEWS +++ b/NEWS @@ -34,6 +34,13 @@ New Functionality See https://docs.zeek.org/en/master/frameworks/logging.html#filter-log-records for more details. +- A new ``zeek_script_args`` variable contains a list of arguments passed + to a script. E.g. either when explicitly executing Zeek like + ``zeek -- myscript.zeek -arg1 -arg2``, or when using Zeek as to interpret + executable scripts that contain a hashbang line at the top like:: + + #!/usr/local/zeek/bin/zeek -- + Changed Functionality --------------------- diff --git a/scripts/base/init-bare.zeek b/scripts/base/init-bare.zeek index 02887b38a5..40bda1d217 100644 --- a/scripts/base/init-bare.zeek +++ b/scripts/base/init-bare.zeek @@ -455,15 +455,15 @@ type connection: record { }; ## Arguments given to Zeek from the command line. In order to use this, Zeek -## must use the "--" command line argument, then give the script name immediately -## after the double hyphens and the provide the arguments after that. For example: -## +## must use a ``--`` command line argument immediately followed by a script +## file and additional arguments after that. For example:: +## ## zeek --bare-mode -- myscript.zeek -a -b -c -## +## ## To use Zeek as an executable interpreter, include a line at the top of a script -## like the following and make the script executable: -## -## #!/usr/local/zeek/bin/zeek -- +## like the following and make the script executable:: +## +## #!/usr/local/zeek/bin/zeek -- const zeek_script_args: vector of string = vector(); ## Default amount of time a file can be inactive before the file analysis diff --git a/src/NetVar.cc b/src/NetVar.cc index b8985456ae..dfc52e0ea4 100644 --- a/src/NetVar.cc +++ b/src/NetVar.cc @@ -30,8 +30,6 @@ zeek::VectorType* index_vec; zeek::VectorType* mime_matches; zeek::RecordType* mime_match; -zeek::VectorVal* zeek_script_args; - zeek::RecordType* socks_address; zeek::TableVal* tcp_reassembler_ports_orig; diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index c155e6fdd3..4d731a507c 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -663,7 +663,7 @@ SetupResult setup(int argc, char** argv, Options* zopts) // Assign the script_args for command line processing in Zeek scripts. if ( ! options.script_args.empty() ) { - auto script_args_val = zeek::id::find_val("zeek_script_args")->AsVectorVal(); + auto script_args_val = id::find_val("zeek_script_args"); for ( const string& script_arg : options.script_args ) { script_args_val->Assign(script_args_val->Size(), make_intrusive(script_arg)); diff --git a/testing/btest/Baseline/core.scripts-args/.stdout b/testing/btest/Baseline/core.script-args/out similarity index 50% rename from testing/btest/Baseline/core.scripts-args/.stdout rename to testing/btest/Baseline/core.script-args/out index c7b3e4ce24..e7be66720c 100644 --- a/testing/btest/Baseline/core.scripts-args/.stdout +++ b/testing/btest/Baseline/core.script-args/out @@ -1 +1,2 @@ [-a, -b, -c] +[-d, -e, -f] diff --git a/testing/btest/core/script-args.zeek b/testing/btest/core/script-args.zeek new file mode 100644 index 0000000000..2e38f411cc --- /dev/null +++ b/testing/btest/core/script-args.zeek @@ -0,0 +1,14 @@ +# @TEST-EXEC: printf '#!' > test.zeek +# @TEST-EXEC: printf "$BUILD/src/zeek -b --\n" >> test.zeek +# @TEST-EXEC: cat %INPUT >> test.zeek +# @TEST-EXEC: chmod u+x test.zeek + +# @TEST-EXEC: zeek -b -- %INPUT -a -b -c >out +# @TEST-EXEC: $(dirname %INPUT)/test.zeek -d -e -f >>out + +# @TEST-EXEC: btest-diff out + +event zeek_init() + { + print zeek_script_args; + } diff --git a/testing/btest/core/scripts-args.zeek b/testing/btest/core/scripts-args.zeek deleted file mode 100644 index 4541ef8e0d..0000000000 --- a/testing/btest/core/scripts-args.zeek +++ /dev/null @@ -1,9 +0,0 @@ -# @TEST-EXEC: zeek -b -- %INPUT -a -b -c - -# @TEST-EXEC: btest-diff .stdout - -event zeek_init() - { - print zeek_script_args; - } -