V
V
vldud2019-03-20 11:45:58
bash
vldud, 2019-03-20 11:45:58

Declaring a variable in a separate script and connecting the script through source is not identical to a simple variable declaration?

There is a bash script:

#!/bin/bash
source "var.conf";
echo bar"$VAR$VAR"bar;
VAR=foo;
echo bar"$VAR$VAR"bar;

variable VAR is declared in var.conf:
VAR=foo
Result of script execution:
barfoo
barfoofoobar

Why do the results of echo bar"$VAR$VAR"bar; various?
UPD: The choice of the string translation directive turned out to be the cause of the bug. We choose crlf, put an empty line after the line with the variable declaration in var.conf and it's done.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xotkot, 2019-03-20
@vldud

$ bash --version 
GNU bash, версия 5.0.2(1)-release (x86_64-pc-linux-gnu)
...

$ ./script.sh 
barfoofoobar
barfoofoobar

your script works as it should, maybe there is a typo somewhere or something

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question