Underline between two variables

1

I have the following code in a .sh file:

echo "$pasta/Dados/$MA/$ano\_$mes/$tabela" 

With all variables set correctly. However, there you run the script, echo results in

data-integration/Dados/MA1/2015\_11/HT_MA1_ESS_SEG

While I would like the result to be

data-integration/Dados/MA1/2015_11/HT_MA1_ESS_SEG

Is there any other syntax for this situation? Thank you.

    
asked by anonymous 12.02.2016 / 20:57

1 answer

1

One possibility is to put the name of the variables between keys {} :

#!/bin/sh

pasta="data-integration"
MA="MA1"
ano="2015"
mes="11"
tabela="HT_MA1_ESS_SEG"

echo "$pasta/Dados/$MA/${ano}_${mes}/$tabela"

Running the above program, the output is:

data-integration/Dados/MA1/2015_11/HT_MA1_ESS_SEG

tested with GNU bash, version 4.3.42

    
12.02.2016 / 22:49