hi
is it posible to print the value NUM
(100
) , while I must use only '
and not "
# NUM=100
# PARAM='some text $NUM'
# echo $PARAM
some text $value
the right print
some text 100
hi
is it posible to print the value NUM
(100
) , while I must use only '
and not "
# NUM=100
# PARAM='some text $NUM'
# echo $PARAM
some text $value
the right print
some text 100
Use double quotes in place of single quotes as single quotes do not allow variable interpolation:
NUM=100
PARAM="some text $NUM"
echo $PARAM
EDIT: Since I'm not allowed to use double quote, you can use concatenation as:
NUM=100
PARAM='some text '$NUM
echo $PARAM
extremely unsafe, but: eval echo $PARAM
I would strongly advise against this: what if param contains some destructive command in backticks? Either re-think your design or re-think your implementation language.
You could at least escape backticks and $()
constructs first:
NUM=100
PARAM='this is $NUM -- `rm foo` -- $(rm bar)'
param_safer=$(echo "$PARAM" | sed 's/`/\\`/g; s/\$(\([^)]\+\))/\\$\\(\1\\)/g')
eval echo "$param_safer"
outputs: this is 100 -- `rm foo` -- $(rm bar)