I am having some trouble running a script to ssh to a remote server. If I simply ssh from the command line I have no trouble reaching the server, but when I run a script to do this I get an error, Name or service not knownname. I have added the IP address and host name to /etc/hosts and that did not help. My script is simply: #!/bin/bash ssh username@hostnameAm I doing something wrong? I'm just learning to write scripts for bash, so I can't say I really know what I'm doing. Obviously I don't need a script just for this, but I'm going to add commands to execute once I get this working.
shell script edited on windows displays unexpected error message
bash;windows;newlines
The problem with the script is that when copying a file from another system like Windows, it adds a newline \n and a carriage return \r\n. For more about line feeds see newline entry on wikipedia.To demonstrate the issue I've uploaded short fragment here which explains how to solve the problem.In short: Use tr to remove those weird line endingstr -d \\r <yourscript>newscript && mv newscript yourscriptThen run the script again.Or as artm suggested.While being in vim editor, use:set ff=unix (ff is short for fileformat) and save the file by shift+zz.