0

I met a weird problem when I tried to "echo" something in my shell. I got a config file and a shell:

foo.config:

mypath="/home/my/path"

bar.sh:

#!/bin/bash
source foo.config
echo "${mypath}ABC"

I expect the result to be

/home/my/pathABC

but it turns out to be

ABCme/my/path

Yes, seems the chars after the variable $path is rewriting the line. Or say, ${mypath} resets the printer's pointer to the beginning of the line.

Of course, if I copy the declaration of mypath to bash file instead of using source, everything will be fine.

I tested on Ubuntu 22.04, Ubuntu 18.04 and Rocky 8.4.

Could anyone explain why the variables imported by "source" will act like this, and how to avoid the rewriting to get the "expected result"?

lida ZHAO
  • 55
  • 1
  • 5

0 Answers0