Shell script suddenly not working

I've been having a shell script working file with no changes in the last month( which is actually stored in git repo).

But today when i run it is giving these errors:

% sh minify.sh
: not found1: minify.sh:
: not found2: minify.sh:
minify.sh: 3: set: Illegal option -

When I removed the 3rd line again a new bunch of errors. Yesterday some sever problem was there as Mysql crashed twice. Mine is Ubuntu 12.04.4 LTS

Here is the script code:

set -x

tmp1=/tmp/__fdsfdsf11.js
tmp2=/tmp/__fdsfdsf22.js

rm -f $tmp1 $tmp2 /tmp/vars.log /tmp/funcs.log

bankstr=""

files="$bankstr myscript.js options.js user-selections.js background.js common.js client_server_common.js  injected/remove-alert.js"

for i in  $files
do
        cat $i| /home/ragu/railways/jsparser/collectSymbols> $tmp2
        cat $i| php /home/ragu/railways/jsparser/find_patterns.php >> /tmp/funcs.log

if [ ! -f $i ]
then
echo "$i not found! ..."
exit 1
fi
done

for i in $files
do
        cat $i| php /home/raggupta/railways/jsparser/replace.php> $tmp1
        yui-compressor $tmp1 > $i
done
rm $tmp1

1 Reply

This is mostly a guess, but your script may have carriage returns (CR) that are screwing things up. Linux and Unix use a linefeed (LF) to mark the end of a line, while Windows uses a CR and an LF. This causes problems when editing the same file on both Windows and Linux.

You can check this by running cat -v minify.sh - if you see "^M" at the end of each line, then that's the problem. It can be fixed with recode IBM-PC..latin1 minify.sh or sed -i 's/\r$//' minify.sh.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct