0

I'm creating a script for CentOS 7 but I'm struggling to concatenate values ​​based on variables, unlike other distributions that I worked. For example, in the code below:

DIR_BKP=/tmp/_bkp_local
PATH_LOG=$DIR_BKP/logs
echo $PATH_LOG

when I run, prints

/logs_bkp_local

As you can see, the echo returns mixing between the initial value of the overlapping variable with the new value.

I've tried

PATH_LOG="$DIR_BKP/logs"
PATH_LOG=${DIR_BKP}/logs

all print the same thing.

How can I do this simple task in CentOS?

Rogério Arantes
  • 712
  • 1
  • 8
  • 29
  • Outputs as expected for me, though I only tested on CentOS 6.8 instead of 7. Did you try echoing $DIR_BKP on its own, to make sure it actually contains what you expect? – Nameless Voice Oct 07 '16 at 20:39
  • I guess you edited your script on a Wintendo box. Probable duplicate of [bash script always prints "Command Not Found"](http://stackoverflow.com/questions/7362504/bash-script-always-prints-command-not-found) – tripleee Oct 09 '16 at 18:00
  • Nameless Voice, echo the $DIR_BKP print correctly, ie, "/tmp/_bkp_local" – Rogério Arantes Oct 10 '16 at 13:59
  • tripleee, did not understand what you mean by Wintendo Box, and I'm not with the error "Command not found" – Rogério Arantes Oct 10 '16 at 14:01

1 Answers1

0

Running the commands directly in the shell, everything works fine, the problem only occurred when performing commands via script. To get to work, I had to use the "export", like this:

export DIR_BKP=/tmp/_bkp_local
export PATH_LOG=${DIR_BKP}/logs
echo $DIR_BKP
echo $PATH_LOG

Prints:
/tmp/_bkp_local
/tmp/_bkp_local/logs
Rogério Arantes
  • 712
  • 1
  • 8
  • 29