Underline between two variables

Asked

Viewed 36 times

1

I have the following code in a file . sh:

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

With all variables set correctly. However, running 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.

1 answer

1


One possibility is you put the name of 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

  • It worked perfectly! Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.