anchor.diff:                  [{"RELX_REPLACE_OS_VARS", "1"},
                    {"NODENAME", "node2"},
                    {"COOKIE", "cookie2"}]),
  +    ok.
  +
  +replace_os_vars_default_env(Config) ->
  +    LibDir1 = proplists:get_value(lib1, Config),
  +
  +    rlx_test_utils:create_app(LibDir1, "goal_app", "0.0.1", [stdlib,kernel], []),
  +
  +    ConfigFile = filename:join([LibDir1, "relx.config"]),
  +    SysConfigSrc = filename:join([LibDir1, "sys.config.src"]),
  +    VmArgs = filename:join([LibDir1, "vm.args.src"]),
  +
  +    rlx_test_utils:write_config(ConfigFile,
  +                 [{release, {foo, "0.0.1"},
  +                   [goal_app]},
  +                  {lib_dirs, [filename:join(LibDir1, "*")]},
  +                  {sys_config_src, SysConfigSrc},
  +                  {vm_args_src, VmArgs},
  +                  {generate_start_script, true},
  +                  {extended_start_script, true}
  +                 ]),
  +
  +    %% new with sys.config.src it doesn't have to be valid Erlang
  +    %% until after var replacemen at runtime.
  +    ec_file:write(VmArgs, "-sname ${NODENAME:-node1}@localhost\n\n"
  +                          "-setcookie ${COOKIE:-cookie1}\n"),
  +
  +    ec_file:write(SysConfigSrc,"[{goal_app, [{var1, ${VAR1:-222}},
  +                                             {var2, \"${VAR2:-201:-test2}\"},
  +                                             {var3, \"${VAR3:-VA:-test3}\"},
  +                                             {var4, \"${VAR4:-VAR4:-test4}\"},
  +                                             {var5, \"${VAR5}\"},
  +                                             {var6, \"${VAR6:-test6:-6}\"},
  +                                             {var7, \"${VAR7:-test7:-7:-7}\"}
  +                                             ]}]."),
  +
  +    OutputDir = filename:join([proplists:get_value(priv_dir, Config),
  +                               rlx_test_utils:create_random_name("relx-output")]),
  +
  +    {ok, _State} = relx:do([{relname, foo},
  +                           {relvsn, "0.0.1"},
  +                           {goals, []},
  +                           {lib_dirs, [LibDir1]},
  +                           {log_level, 3},
  +                           {output_dir, OutputDir},
  +                           {config, ConfigFile}], ["release"]),
  +
  +    {ok, _} = sh(filename:join([OutputDir, "foo", "bin", "foo start"]),
  +                 [{"RELX_REPLACE_OS_VARS", "1"},
  +                  {"NODENAME", "node1"},
  +                  {"VAR5", "test5"}]),
  +    timer:sleep(?SLEEP_TIME),
  +    {ok, "pong"} = sh(filename:join([OutputDir, "foo", "bin", "foo ping"]),
  +                 [{"RELX_REPLACE_OS_VARS", "1"},
  +                  {"VAR5", ""}]),
  +
  +    {ok, "222"} = sh(filename:join([OutputDir, "foo", "bin",
  +                                       "foo eval '{ok, V} = application:get_env(goal_app, var1), V.'"]),
  +                        [{"RELX_REPLACE_OS_VARS", "1"},
  +                         {"VAR5", "test5"}]),
  +    {ok, "\"201:-test2\""} = sh(filename:join([OutputDir, "foo", "bin",
  +                                       "foo eval '{ok, V} = application:get_env(goal_app, var2), V.'"]),
  +                        [{"RELX_REPLACE_OS_VARS", "1"}]),
  +    {ok, "\"VA:-test3\""} = sh(filename:join([OutputDir, "foo", "bin",
  +                                       "foo eval '{ok, V} = application:get_env(goal_app, var3), V.'"]),
  +                        [{"RELX_REPLACE_OS_VARS", "1"}]),
  +    {ok, "\"VAR4:-test4\""} = sh(filename:join([OutputDir, "foo", "bin",
  +                                       "foo eval '{ok, V} = application:get_env(goal_app, var4), V.'"]),
  +                        [{"RELX_REPLACE_OS_VARS", "1"}]),
  +    {ok, "\"test5\""} = sh(filename:join([OutputDir, "foo", "bin",
  +                                       "foo eval '{ok, V} = application:get_env(goal_app, var5), V.'"]),
  +                        [{"RELX_REPLACE_OS_VARS", "1"},
  +                         {"VAR5", "test5"}]),
  +    {ok, "\"test5\""} = sh(filename:join([OutputDir, "foo", "bin",
  +                                       "foo eval '{ok, V} = application:get_env(goal_app, var5), V.'"]),
  +                        [{"RELX_REPLACE_OS_VARS", "1"},
  +                         {"VAR5", ""}]),
  +    {ok, "\"test6:-6\""} = sh(filename:join([OutputDir, "foo", "bin",
  +                                       "foo eval '{ok, V} = application:get_env(goal_app, var6), V.'"]),
  +                        [{"RELX_REPLACE_OS_VARS", "1"},
  +                         {"VAR5", ""}]),
  +    {ok, "\"test7:-7:-7\""} = sh(filename:join([OutputDir, "foo", "bin",
  +                                       "foo eval '{ok, V} = application:get_env(goal_app, var7), V.'"]),
  +                        [{"RELX_REPLACE_OS_VARS", "1"},
  +                         {"VAR5", ""}]),
  +    {ok, "\"node1\""} = sh(filename:join([OutputDir, "foo", "bin",
  +                                     "foo eval '[Node,_] = re:split(atom_to_list(node()), \"@\"),binary_to_list(Node).'"]),
  +                        [{"RELX_REPLACE_OS_VARS", "1"},
  +                         {"NODENAME", "node1"}]),
  +    {ok, "cookie1"} = sh(filename:join([OutputDir, "foo", "bin",
  +                                       "foo eval 'erlang:get_cookie().'"]),
  +                         [{"RELX_REPLACE_OS_VARS", "1"}]),
  +    {ok, _Node1} = sh(filename:join([OutputDir, "foo", "bin",
  +                                       "foo eval 'atom_to_list(node()).'"]),
  +                         [{"RELX_REPLACE_OS_VARS", "1"},
  +                          {"NODENAME", "node1"},
  +                          {"COOKIE", "cookie1"}]),
  +    %% check that the replaced files have been created in the right place
  +    ?assert(ec_file:exists(filename:join([OutputDir, "foo", "releases", "0.0.1",
  +                                          "sys.config"]))),
  +    {ok, _} = sh(filename:join([OutputDir, "foo", "bin", "foo stop"]),
  +                [{"RELX_REPLACE_OS_VARS", "1"},
  +                 {"NODENAME", "node1"},
  +                 {"COOKIE", "cookie1"}]),
  +
  +    timer:sleep(?SLEEP_TIME),
  +
  +    %% start the node again but this time with overriding all default env values
  +    {ok, _} = sh(filename:join([OutputDir, "foo", "bin", "foo start"]),
  +                 [{"RELX_REPLACE_OS_VARS", "1"},
  +                  {"NODENAME", "node1"},
  +                  {"COOKIE", "cookie1"},
  +                  {"VAR1", "2222"},
  +                  {"VAR2", "201:-test2-2"},
  +                  {"VAR3", "VA:-test3-2"},
  +                  {"VAR4", "VAR4:-test4-2"},
  +                  {"VAR5", "test5-2"},
  +                  {"VAR6", "test6:-6-2"},
  +                  {"VAR7", "test7:-7:-7-2"}]),
  +    timer:sleep(?SLEEP_TIME),
  +    {ok, "pong"} = sh(filename:join([OutputDir, "foo", "bin", "foo ping"]),
  +                 [{"RELX_REPLACE_OS_VARS", "1"},
  +                  {"VAR5", ""}]),
  +
  +    {ok, "2222"} = sh(filename:join([OutputDir, "foo", "bin",
  +                                       "foo eval '{ok, V} = application:get_env(goal_app, var1), V.'"]),
  +                        [{"RELX_REPLACE_OS_VARS", "1"},
  +                         {"VAR5", "test5"}]),
  +    {ok, "\"201:-test2-2\""} = sh(filename:join([OutputDir, "foo", "bin",
  +                                       "foo eval '{ok, V} = application:get_env(goal_app, var2), V.'"]),
  +                        [{"RELX_REPLACE_OS_VARS", "1"}]),
  +    {ok, "\"VA:-test3-2\""} = sh(filename:join([OutputDir, "foo", "bin",
  +                                       "foo eval '{ok, V} = application:get_env(goal_app, var3), V.'"]),
  +                        [{"RELX_REPLACE_OS_VARS", "1"}]),
  +    {ok, "\"VAR4:-test4-2\""} = sh(filename:join([OutputDir, "foo", "bin",
  +                                       "foo eval '{ok, V} = application:get_env(goal_app, var4), V.'"]),
  +                        [{"RELX_REPLACE_OS_VARS", "1"}]),
  +    {ok, "\"test5-2\""} = sh(filename:join([OutputDir, "foo", "bin",
  +                                       "foo eval '{ok, V} = application:get_env(goal_app, var5), V.'"]),
  +                        [{"RELX_REPLACE_OS_VARS", "1"},
  +                         {"VAR5", "test5-2"}]),
  +    {ok, "\"test5-2\""} = sh(filename:join([OutputDir, "foo", "bin",
  +                                       "foo eval '{ok, V} = application:get_env(goal_app, var5), V.'"]),
  +                        [{"RELX_REPLACE_OS_VARS", "1"},
  +                         {"VAR5", ""}]),
  +    {ok, "\"test6:-6-2\""} = sh(filename:join([OutputDir, "foo", "bin",
  +                                       "foo eval '{ok, V} = application:get_env(goal_app, var6), V.'"]),
  +                        [{"RELX_REPLACE_OS_VARS", "1"},
  +                         {"VAR5", ""}]),
  +    {ok, "\"test7:-7:-7-2\""} = sh(filename:join([OutputDir, "foo", "bin",
  +                                       "foo eval '{ok, V} = application:get_env(goal_app, var7), V.'"]),
  +                        [{"RELX_REPLACE_OS_VARS", "1"},
  +                         {"VAR5", ""}]),
  +    {ok, "\"node1\""} = sh(filename:join([OutputDir, "foo", "bin",
  +                                     "foo eval '[Node,_] = re:split(atom_to_list(node()), \"@\"),binary_to_list(Node).'"]),
  +                        [{"RELX_REPLACE_OS_VARS", "1"},
  +                         {"NODENAME", "node1"}]),
  +    {ok, "cookie1"} = sh(filename:join([OutputDir, "foo", "bin",
  +                                       "foo eval 'erlang:get_cookie().'"]),
  +                         [{"RELX_REPLACE_OS_VARS", "1"}]),
  +    {ok, _Node1} = sh(filename:join([OutputDir, "foo", "bin",
  +                                       "foo eval 'atom_to_list(node()).'"]),
  +                         [{"RELX_REPLACE_OS_VARS", "1"},
  +                          {"NODENAME", "node1"},
  +                          {"COOKIE", "cookie1"}]),
  +    %% check that the replaced files have been created in the right place
  +    ?assert(ec_file:exists(filename:join([OutputDir, "foo", "releases", "0.0.1",
  +                                          "sys.config"]))),
  +    {ok, _} = sh(filename:join([OutputDir, "foo", "bin", "foo stop"]),
  +                [{"RELX_REPLACE_OS_VARS", "1"},
  +                 {"NODENAME", "node1"},
  +                 {"COOKIE", "cookie1"}]),
       ok.
   
   custom_start_script_hooks(Config) ->
  
positive.code:              remote_console, shortname_remote_console, replace_os_vars, replace_os_vars_sys_config_vm_args_src, replace_os_vars_multi_node,
               replace_os_vars_included_config,
               replace_os_vars_custom_location, replace_os_vars_dev_mode, replace_os_vars_twice,
               custom_start_script_hooks, custom_start_script_hooks_console,
               builtin_wait_for_vm_start_script_hook, builtin_pid_start_script_hook,
               builtin_wait_for_process_start_script_hook, mixed_custom_and_builtin_start_script_hooks,
  
negative.code:          replace_os_vars_custom_location/1,
           replace_os_vars_dev_mode/1,
           replace_os_vars_twice/1,
           replace_os_vars_default_env/1,
           custom_start_script_hooks/1,
           custom_start_script_hooks_console/1,
           builtin_wait_for_vm_start_script_hook/1,
  