Bash function, export function argument as environment variable -
i wrote bash function export environment variable. first function argument variable name, second variable value. want echo
show value exported:
#!/bin/bash env_var_export() { export $1=$2 echo "" echo " export $1=$$1" echo "" } env_var_export var defaultval456
i mean, echo should print: export var=defaultval456
. help? know can this:
echo "" echo " export $1=$2" echo ""
but not solution problem.
$$
special variable expands shell's pid, , that's going evaluated in echo
. should instead use indirect reference this:
echo "" echo " export $1=${!1}" echo ""
this syntax take variable named in $1
, lookup value based on name (i.e. indirection).
Comments
Post a Comment