Last active
August 29, 2015 14:23
-
-
Save janl/67ab4f9efd89ecec4030 to your computer and use it in GitHub Desktop.
string interpolation / variable substitution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -ex | |
# I have a variable that’s a string, that includes the expansion for another variable, albeit quited: `\${foo}` | |
# how can I get a string that is that original string, but with the variable expanded? | |
# no bashisms allowed, this needs to be stock-sh. | |
var1=foo | |
var2=\${var1}/bar | |
# insert magic here | |
eval var3=$var2 | |
echo $var3 # prints `foo/bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Think what you want is:
But that's a bashism afaik. See: http://stackoverflow.com/a/11065196, in particular: