N
N
Nikita Nafranets2016-03-07 04:56:29
bash
Nikita Nafranets, 2016-03-07 04:56:29

Why doesn't Cygwin read the script correctly?

Yesterday, with grief, I wrote my first script

#!/bin/bash
mkdir jpg_m;
mkdir watermark;
for file in *.jpg
do 
  convert $file -resize 300x300 jpg_m/"`basename $file .jpg`_m.jpg"
done;
for file in jpg_m/*.jpg
do 
  width=$(identify -format %w $file)
  composite -dissolve 65% -gravity center -quality 100 \( d:/Work/watermarks/logo.png -resize $(( $width / 100 * 90 )) \) $file watermark/"`basename $file .jpg`.jpg"
done;
for file in *.jpg
do
  width=$(identify -format %w $file)
  composite -dissolve 70% -gravity center -quality 100 \( d:/Work/watermarks/logo.png -resize $(( $width / 100 * 90 )) \) $file watermark/"`basename $file .jpg`.jpg"
done;
for file in '*[^m)]'.jpg
do 
  convert $file -resize 170x250 "`basename $file .jpg`_s.jpg"
done;
for file in *_s.jpg
do 
  width=$(identify -format %w $file)
  composite -dissolve 70% -gravity center -quality 100 \( d:/Work/watermarks/logo.png -resize $width \) $file watermark/"`basename $file .jpg`.jpg"
done;
for file in watermark/*.jpg
do 
  curl -T $file ftp://test
done;

I ran this script through mintty, which came with the installation with GIT. But I found a problem, it does not calculate decimal values. Got into Google found out that we need BC, tried to use this bc in bash from git and gave me that he does not know what it is. I started looking for how to put bc on this bash, but I did not find it. But I found Cygwin which can install this bc. Installed cygwin, installed bc, tried this bc. Works! I paste the code into the script, run it and get
2
3
4
5
6
7
8
9
10
11
12
13
14
15
d:/Work/scripts/sh/script.sh: line 2: $'\r': команда не найдена
d:/Work/scripts/sh/script.sh: line 3: $'\r': команда не найдена
d:/Work/scripts/sh/script.sh: line 5: $'\r': команда не найдена
': Invalid argument @ error/blob.c/OpenBlob/2702.
_.dll': No such file or directory @ warning/module.c/GetMagickModulePath/674.16\modules\coders\IM_MOD_RL_JPG
' @ error/constitute.c/ReadImage/501.his image format `JPG
' @ error/convert.c/ConvertImageCommand/3252.
d:/Work/scripts/sh/script.sh: line 7: $'\r': команда не найдена
d:/Work/scripts/sh/script.sh: line 9: $'\r': команда не найдена
': Invalid argument @ error/blob.c/OpenBlob/2702.
_.dll': No such file or directory @ warning/module.c/GetMagickModulePath/674.Q16\modules\coders\IM_MOD_RL_JPG
' @ error/constitute.c/ReadImage/501.this image format `JPG
 / 100 * 90 ")ошибка синтаксиса: ожидается операнд (error token is "
d:/Work/scripts/sh/script.sh: line 13: syntax error near unexpected token `$'do\r''
':/Work/scripts/sh/script.sh: line 13: `do

I understand that Cygwin takes my \r (next line) as code. How can I fix this situation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2016-03-07
@Dimensi

Your editor saved the file in DOS format, where the end of the line is indicated by a pair of CRLF characters. You need to resave in UNIX format with one LF character.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question