0

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

Codenvy command

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?

4

1 回答 1

1

您的文件很可能有\r\n行尾,应将其更改为\n行尾。

使用命令行实用程序转换文件的简单方法sed如下。

sed -i 's/\r\n/\n/g' "./path/to/file"(未经测试)。


通常,Windows 应用程序使用“回车”和“换行”字符来终止文本文件中的行,通常写为转义码\r\n

另一方面,类 Unix 系统仅使用换行符来终止行,或者 new 作为行结尾,Unix 仅使用 'line feed' 字符\n

见:http ://www.cs.toronto.edu/~krueger/csc209h/tut/line-endings.html


笔记:

作为补充说明,如果要执行脚本,则应始终在脚本顶部添加 shebang,否则如果要单独获取脚本,则不要添加。#!/bin/bash用于 bash 脚本,以及#!/bin/sh可移植或符合 POSIX 的脚本。

于 2019-08-02T18:29:12.133 回答