0

Anoyone knows of alternative to CygWin that is not WSL and is cappable of running simple bash scripts properly?

#!/bin/sh
A="X Y"
A+=" Z"
echo "$A"

Returns " Y Z" instead of "X Y Z" as it should.

Code taken from https://stackoverflow.com/a/4182643/10869266 enter image description here

1 Answers1

0

The problem is due to not having a file with proper line termination

$ file prova.sh
prova.sh: POSIX shell script, ASCII text executable

$ cat prova.sh
#!/bin/sh
A="X Y"
A+=" Z"
echo "$A"

$ bash prova.sh
X Y Z

however

$ cp prova.sh prova2.sh

$ u2d prova2.sh
unix2dos: converting file prova2.sh to DOS format...

 $ file prova2.sh
prova2.sh: POSIX shell script, ASCII text executable, with CRLF line terminators

$ bash prova2.sh
 ZY

use d2u to convert to the proper format. It is in the dos2unix package

$ cygcheck -p usr/bin/d2u
...
dos2unix-7.4.2-1 - dos2unix: Line Break Conversion
matzeri
  • 8,062
  • 2
  • 15
  • 16