Harsh Harsh - 4 years ago 79
Bash Question

How to manipulate a variable name in Bash?

I have a variable name in Bash as:

var=(any_word)_SuSE_11_design_guides


I want to manipulate the name such that I can have:

x=$(echo "$var" | some operation)
echo $x
SuSE_11_design_guides


Basically I want to remove every character behind first
_
when detected. How to achieve this?

Answer Source

I think you meant retain Everything behind first _ , which can be achieved using parameter-expansion.

string="(anyword)_SuSE_11_design_guides"
printf "%s\n" "${string#*_}"
SuSE_11_design_guides
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download