I am storing bash scripts onto a CentOS server from PHP over SSH2; I know it is complicated, but just bear with me.
When I open up the file (on the server):
vi myScript
I see:
ls -al^M
free -m
So, when I try an execute it with:
bash myScript
The output throws an error:
ls: invalid option --
Try `ls --help' for more information.
total used free shared buffers cached
Mem: 676 642 34 0 33 313
-/+ buffers/cache: 295 380
Swap: 767 1 766
What is the ^M and any idea where it is coming from? The bash script should to be able to support newlines and tabs.
Thanks.
^M is end of line coming from Windows. The file was created in Windows initially. You may do in vi something like :1,$ s/^v^M//g to delete those.
Also you can use
dos2unixcommand on the entire file to clean it in one shot. You can do it before execution of script.