Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • Which approach would you recommend with shell? As ${!<varable name>} is not supported by shell. Commented Jan 16, 2023 at 12:53
  • 1
    @Freddy, eval echo "\$${var3}" works fine in the sh shell. Or, does your system have bash? Type in bash --version at the command-line. If it returns with a version number, you have bash. Add #!/usr/bin/env bash to the top of your bash script, like I do in eRCaGuy_hello_world/bash/hello_world_basic.sh, to force that script to use bash, and then use echo "${!var3}" instead. Commented Jan 16, 2023 at 16:28
  • I though maybe there is a way to avoid eval in sh shell but then eval echo "\$${var3}" it is. Commented Jan 18, 2023 at 22:08
  • 1
    @Freddy, if you post it as a question, put a link back here so I can follow the question too, but I don't think there's another way in sh, but I'm no expert on the matter. Commented Jan 18, 2023 at 22:14