Codenvy is an IDE that removes all files that are in gitignore when the environment you work in goes to sleep. So every time I start working in Codenvy I need to put these files back. That is a hassle and therefore I am trying to add what in Codenvy is called a command (a script) for this.
I have the following:
1. cp vars-user-portal/variables.env user-portal/variables.env
2.
3. cp vars-user-portal/serviceAccountKey.json user-portal/serviceAccountKey.json
4.
5. cp vars-user-portal/.env user-portal/client/.env
6.
7. cd user-portal && npm install
8.
9. cd user-portal/client && npm install
10.
11. xdg-open user-portal/client/.env
When I run this command, I get the output:
/bin/bash: line 1: $'\r': command not found
/bin/bash: line 3: $'\r': command not found
/bin/bash: line 5: $'\r': command not found
Usage: npm <command>
...
Did you mean one of these?
install
uninstall
unstar
/bin/bash: line 7: $'\r': command not found
Usage: npm <command>
...
/bin/bash: line 9: $'\r': command not found
xdg-open: file '.env' does not exist
I have the impression that when there are spaces on a line it sees it as separate commands. Any idea how I can get this script to work?
Your file most likely has \r\n
line endings, which should be changed to \n
line endings.
A simple way to convert the file with the command line sed
utility is as follows.
sed -i 's/\r\n/\n/g' "./path/to/file"
(Untested).
In general, Windows applications terminate lines in text files with the 'carriage return' and 'line feed' characters, commonly written as the escape codes \r\n
.
On the other hand, Unix-like systems terminate lines with only the line feed, or new as a line ending, which Unix uses just 'line feed' character \n
.
See: http://www.cs.toronto.edu/~krueger/csc209h/tut/line-endings.html
Note:
As an additional mention, you should always add a shebang to the top of your script if it is to be executable, or else do not add one if it is to be solely sourced. #!/bin/bash
for bash scripts, and #!/bin/sh
for portable or POSIX-compliant scripts.