2

I'm having headaches to know why my script doesn't work as expected under windows subsystem linux.

My version from the store : Debian GNU/Linux 9.6 (stretch) (I tried ubuntu too, with the same results)

And my bash version : GNU bash, version 4.4.12(1)-release (x86_64-pc-linux-gnu)

This is my basic script only to show the issue :

PROJECT_ENV="development"
echo $PROJECT_ENV
compose_file="docker-compose.${PROJECT_ENV}.build.yml"
echo $compose_file

And it outputs :

.build.ymlpose.development

As i understand, that output doesn't make any sense to me, I tried to reinstall bash but i'm still having the same issue.

6

There is a carriage return character at the end of PROJECT_ENV variable content. This is probably because your script uses CR+LF line endings (proper in DOS/Windows) instead of sole LF (Unix/Linux).

In Linux dos2unix is the right tool to fix it.

The detailed explanation is as follows:

  1. The final echo prints

    docker-compose.development
    
  2. CR makes the terminal go back to the beginning of the line.

  3. The consecutive characters overwrite the previous text:

    .build.yml
    
  4. Therefore the result is:

    .build.ymlpose.development
    

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.