0

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}${SCRIPT[$i]}
    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!

softwareRat
  • 57
  • 2
  • 7

1 Answers1

0

It doesn't show here but your script has carriage return chars in the shell definition lines. Edit them out (using Notepad++ for instance or tr -d "\015" < yourscript.sh > newscript.sh)

You can redirect your script to a file you'll see all the text in the file.

Carriage return char (asc 13, \r) just resets the cursor without skipping to newline. Every text written after that overwrites the text in the current line. Windows uses that to complement the linefeed character. Windows text mode is like that

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219