How to join variables in a bash script

To join/concatenate two variables in bash-script use following:

1) “${var1}_${var2}” # here we have joined var1 and var2 separated by ‘_’

2) basePath=”/home/anj/” # base part.
fileName=”myfile.txt” # fitename
fileName=”${basePath}/${fileName}” # separated by /

It is quite simple just place each variable adjacent to each other.
${basePath}/${fileName}” avoid variable substitution issues (if any).

Leave a Reply

Your email address will not be published. Required fields are marked *.

*
*
You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>