dimanche 28 août 2016

Weird behavior in bashrc: concatenate, same code run/fail

I have a VM with CentOS 6 and I am loading some scripts from bashrc. Everything worked fine, but I wanted to copy-paste the same code and scripts in an older backup of same VM, but I got an error: "unexpected end of file". Also the same error had to deal another person when I wanted to share those scripts with him (he had the same VM).

So I started to debug a little and found that one row he didn't liked it was (it was parsing an array:

COUNTER=1    
while [[ ! -z ${SCRIPT[$COUNTER]} ]]; do 

Also he didn't liked this either (it's not exactly the same with "while" logic, but it does the job):

for i in ${Script[@]}; do

So, I replaced it with:

for ((i = 0; i < ${#SCRIPT[@]}; i++)); do

Now I tryed to get the error name with same piece of code and no more errors occurred.

Also I have this behavior which is the weirdest from all: Code:

BASH_SCRIPTS_LOCATION='/mnt/hgfs/Shared-workspace/scripts/'
SCRIPT[0]='aliases.sh'
SCRIPT[1]='scripts_config.sh'
SCRIPT[2]='credentials.sh'
SCRIPT[3]='other_functions.sh'
SCRIPT[4]='ssh_functions.sh'
SCRIPT[5]='release_functions.sh'
SCRIPT[6]='test_functions.sh'
for ((i = 0; i < ${#SCRIPT[@]}; i++)); do
    loadedScript=${BASH_SCRIPTS_LOCATION}text
    echo -e "$loadedScript"
done

Terminal output (seems the "concatenate" it is replacing the characters starting from the begging of first String/variable :

aliases.shShared-workspace/scripts/
scripts_config.shworkspace/scripts/
credentials.shed-workspace/scripts/
other_functions.shorkspace/scripts/
ssh_functions.sh-workspace/scripts/
release_functions.shkspace/scripts/
test_functions.shworkspace/scripts/

I think I am using something very inappropriate. But I am not sure what or what I should be looking for.

Any recommandation or advice is welcome.

Thanks!




Aucun commentaire:

Enregistrer un commentaire