src/bin/psql/command.c
static backslashResult
exec_command_getenv(PsqlScanState scan_state, bool active_branch,
					const char *cmd)
{
	bool		success = true;

	if (active_branch)
	{
		char	   *myvar = psql_scan_slash_option(scan_state,
												   OT_NORMAL, NULL, false);
		char	   *envvar = psql_scan_slash_option(scan_state,
													OT_NORMAL, NULL, false);

		if (!myvar || !envvar)
		{
			pg_log_error("\\%s: missing required argument", cmd);
			success = false;
		}
		else
		{
			char	   *envval = getenv(envvar);

			if (envval && !SetVariable(pset.vars, myvar, envval))
				success = false;
		}
		free(myvar);
		free(envvar);
	}
	else
		ignore_slash_options(scan_state);

	return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR;
}
/*
 * \getenv -- set variable from environment variable
 */
\getenv -- set variable from environment variable
\ getenv -- set variable from environment variable
static backslashResult
exec_command_getenv(PsqlScanState scan_state, bool active_branch,
					const char *cmd)
{
	bool		success = true;
	if (active_branch)
	{
		char	   *myvar = psql_scan_slash_option(scan_state,
												   OT_NORMAL, NULL, false);
		char	   *envvar = psql_scan_slash_option(scan_state,
													OT_NORMAL, NULL, false);
		if (!myvar || !envvar)
		{
			pg_log_error("\\%s: missing required argument", cmd);
			success = false;
		}
		else
		{
			char	   *envval = getenv(envvar);
			if (envval && !SetVariable(pset.vars, myvar, envval))
				success = false;
		}
		free(myvar);
		free(envvar);
	}
	else
		ignore_slash_options(scan_state);
	return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR;
}
static backslashResult exec_command_getenv ( PsqlScanState scan_state , bool active_branch , const char * cmd ) { bool success = true ; if ( active_branch ) { char * myvar = psql_scan_slash_option ( scan_state , OT_NORMAL , NULL , false ) ; char * envvar = psql_scan_slash_option ( scan_state , OT_NORMAL , NULL , false ) ; if ( ! myvar || ! envvar ) { pg_log_error ( " \\ " , cmd ) ; success = false ; } else { char * envval = getenv ( envvar ) ; if ( envval && ! SetVariable ( pset . vars , myvar , envval ) ) success = false ; } free ( myvar ) ; free ( envvar ) ; } else ignore_slash_options ( scan_state ) ; return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR ; }
\getenv -- set variable from environment variable
\ getenv -- set variable from environment variable