Index: /trunk/FACT++/src/rootifysql.cc
===================================================================
--- /trunk/FACT++/src/rootifysql.cc	(revision 19078)
+++ /trunk/FACT++/src/rootifysql.cc	(revision 19079)
@@ -36,5 +36,6 @@
         ("no-fill",       po_switch(),                 "Do not fill events into the root file (mainly for debugging purposes, e.g. performance studies)")
         ("delimiter",     var<string>(""),             "The delimiter used if contents are displayed with --display (default=\\t)")
-        ("var.*",         var<string>(),               "Predefined user variables")
+        ("var.*",         var<string>(),               "Predefined SQL user variables (@VAR)")
+        ("env.*",         vars<string>(),              "Predefined environment for substitutions in the query ($ENV)")
         ("verbose,v",     var<uint16_t>(1),            "Verbosity (0: quiet, 1: default, 2: more, 3, ...)")
         ;
@@ -80,4 +81,10 @@
         "You can use variables in your sql query like @MyVar and define them on the "
         "command line. In this example with --var.MyVar=5\n"
+        "\n"
+        "You can use environment definitions for substitutions in your SQL query. "
+        "For example --env.TEST=5 would replace $TEST or ${TEST} in your query by 5."
+        "If you specifiy one environmentvariable more than once, a list is created. "
+        "For example --env.TEST=1 --env.TEST=2 --env.TEST=3 would substitute "
+        "$TEST or ${TEST} by '1, 2, 3'. This is useful for the SQL `IN` keyword.\n"
         "\n"
         "Comments in the query-file can be placed according to the SQL standard inline "
@@ -121,4 +128,5 @@
     const vector<string> _ignore = conf.Vec<string>("ignore");
     //const vector<Map> mymap    = conf.Vec<Map>("map");
+
     // -------------------------------------------------------------------------
 
@@ -129,4 +137,6 @@
         variables.emplace_back('@'+var.substr(4)+":="+Tools::Trim(conf.Get<string>(var)));
 
+    // -------------------------------------------------------------------------
+
     if (verbose>0)
         cout << "\n--------------------- Rootify SQL ----------------------" << endl;
@@ -151,4 +161,19 @@
         cerr << "No query specified." << endl;
         return 2;
+    }
+
+    // -------------------------------------------------------------------------
+
+    const auto envs = conf.GetWildcardOptions("env.*");
+
+    for (const auto &env : envs)
+    {
+        regex r1("\\$\\{"+env.substr(4)+"\\}");
+        regex r2("\\$"+env.substr(4)+"\\b");
+
+        const string repl = boost::join(conf.Vec<string>(env), ", ");
+
+        query = regex_replace(query, r1, repl);
+        query = regex_replace(query, r2, repl);
     }
 
