Harsh Harsh - 4 years ago 79
Bash Question

How to manipulate a variable name in Bash?

I have a variable name in Bash as:


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

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

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.

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