bash - Replace Environment Variable in argument to shell script -
i've got shell script gets called arguments contain variable names. want variable replaced values. consider example below: solves problem, uses eval. want avoid eval security reasons.
#!/bin/bash # # example: # $> replace.sh arg '$var' # arg value var=value args=$(eval echo $*) echo $args
works me like:
#!/bin/bash # # example: # $> replace.sh arg '$var' # arg value var=value args="" arg in "$@" arg="${arg/$/}" # remove preceding $ indirect variable expansion work args="${args} ${!arg}" done echo "$args"
Comments
Post a Comment