\r character in shell script

后端 未结 6 1950
执笔经年
执笔经年 2020-11-30 05:05

I get the below error while trying to execute a shell script,

$\'\\r\': command not found: line 2:

Please suggest a solution for the same.

6条回答
  •  爱一瞬间的悲伤
    2020-11-30 05:56

    I got a different error message when running your script under /bin/sh, but when I switched to /bin/bash, it worked fine:

    $ cat foo.sh
    #!/bin/sh
    if [[ $# -lt 1 ]];
        then echo "ERROR Environment argument missing"
        RC=50
        exit $RC
    fi
    $ sh foo.sh
    foo.sh: 6: [[: not found
    $ bash foo.sh
    ERROR Environment argument missing
    

    You've built in a bashism. This may or may not be a big deal for your organization. If you want to keep using bash-specific features, change the shebang line to #!/bin/bash and see if that helps.

提交回复
热议问题