0

I'm wondering is there anyway to use for example , or ^ or % and so on, from variables in Bash ?

in instance I have three variables

var1='hello world'
var2=${var1:3}
var3='^'

I want to do this in bash ! please attention to my question I know it's very simple in other ways but how about this ?

echo ${var1:0:3}${var2$var3} # instead of echo ${var1:0:3}${var2^}

and finally output is :

heLlo world
2
  • Case modification expansion is done before variable expansion. Commented Dec 9, 2019 at 11:34
  • What is the problem that you are trying to solve ? You can use eval, but this may bring security problem. Commented Dec 9, 2019 at 12:52

1 Answer 1

1

In theory, eval can do execute arbitrary code, but has many security issues, so it should be used as last resort. Use it only when you trust the input 100%.

var1='hello world'
var2=${var1:3}
var3='^'

eval echo '${var1:0:3}${var2'$var3'}'
Sign up to request clarification or add additional context in comments.

1 Comment

thnx yes eval is evil 😉 and it's dangerous, repp ++ I'm waiting for other possible ways ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.