I installed Ubuntu bash on my windows machine, so I can test linux scripts away from work. I created a very simple script with basic "hello world" and a change directory (cd), but when executing it displays the hello world. It errors out on the cd to directory line.
Here is the error:
$ ./test.sh
hello world
zipping away
./test.sh: line 6: cd: $'/home/fjaffer/temp\r\r': No such file or directory
./test.sh: line 7: $'\r': command not found
ffr@DP-PC:~$
My script test.sh
is below:
#!/bin/bash
echo "hello world"
echo "zipping away"
dir=/home/fjaffer/temp
cd $dir
Please advise? Thank you.
cd "$dir"
instead of letting the shell word-split the expansion of"$dir"
. Surprised that didn't consume the\r
characters. – Peter Cordes Sep 02 '18 at 16:23IFS
(and it's not "IFS white space"), so it acts like any character, just invisible. – ilkkachu Sep 02 '18 at 16:57