Saturday 13 April 2019

bash - "Syntax error near unexpected token '$'r''" in shell script

I am writing a script am I am getting an error on lines 2-3. The error is printed like this:


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

The file is called ex6.sh. Could someone provide some guidance as to why this error is happening?


#!/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 [ "$1" == "--long" ]; then
echo "--long";
for i in `find` ;
do
if [ -d $i ]; then
echo $i "is a directory";
fi
if [ -f $i ]; then
echo $i "is a file";
fi
done
fi

if [ "$1" == "--rm" ]; then
echo "--rm";
for i in `find` ;
do
if [ -d $i ]; then
echo $i "is a directory";
fi
if [ -f $i ]; then
echo $i "is a file";
fi
done
fi
}

getArgs () {
if [ "$1" == "--long" ]; then
echo "got the first param $1";
else
if [ "$1" == "--rm" ]; then
echo "got the second param $1";
else
if [ "$1" == "" ]; then
echo "got default param";
else
echo "script.sh: unknown option $1";
exit;
fi
fi
fi

}

getArgs $1;
#ARGS=$1;

func $1;

No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...