小编Eri*_*ric的帖子

shell 脚本中的“意外标记 '$'\r'' 附近的语法错误”

我正在编写脚本,但在第 2-3 行出现错误。错误是这样打印的:

./ex6.sh: line2: $'\r': command not found
./ex6.sh: line3: syntax error near unexpected token '$'\r''
./ex6.sh: line3: 'fund ()
Run Code Online (Sandbox Code Playgroud)

该文件名为ex6.sh. 有人可以就为什么会发生此错误提供一些指导吗?

#!/bin/sh

func () 
{
if [ "$1" == "" ]; then
echo "Default";
for i in `find` ; 
do
    if [ -d $i ]; then
        echo $i "is a directory";
    fi
    if [ -f $i ]; then
        if [ "$i" != "./script.sh" ]; then
            echo $i "is a file";        
        fi
    fi
done
fi

if [ …
Run Code Online (Sandbox Code Playgroud)

bash

4
推荐指数
1
解决办法
3万
查看次数

标签 统计

bash ×1