Assigning one variable to another in Bash?


I have a doubt. When i declare a value and assign to some variable, I don’t know how to reassign the same value to another variable. See the code snippet below.

#declare ARG1 to a
#declaring $a to ARG2    

echo "ARG 2 = $ARG2"

It should display my output as

ARG 2 = ARG1

…but instead the actual output is:

line 5: ARG1: command not found
ARG 2 = $


To assign the value associated with the variable dest to the variable source, you need simply run dest=$source.

For example, to assign the value associated with the variable arg2 to the variable a:

echo "ARG 2 = $arg2"

The use of lower-case variable names for local shell variables is by convention, not necessity — but this has the advantage of avoiding conflicts with environment variables and builtins, both of which use all-uppercase names by convention.

Answered By – Charles Duffy

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published