There is a script for downloading a file from a remote server . At startup, writes Illegal number: 100*1024*1024 . What could be the problem?

 #!/bin/bash u=$1 [ -n "$u" ] || { echo "использование: $0 адрес"; exit 1; } n=0 p="часть" s=100*1024*1024 while true; do printf -vf "%s%0.3d" $p $n echo -n "скачиваем $f" if ! curl -s -f -r $((n*s))-$(((n+1)*s-1)) "$u" > "$f"; then exit $?; fi echo ". готово. следующий номер: $((++n))" done 
  • one
    Do you have a bash? Looks like a dash error: dash -c 's=1+1; echo $((s))' dash -c 's=1+1; echo $((s))' prints dash: 1: Illegal number: 1+1 - Alexey Ten
  • If the reason itself is interesting, the problem is how bash calculates arithmetic expressions. Either google on this topic, or look at your condition with curl `th - there is one of the possible options for the calculation. PS @AlexeyTen, "#! / Bin / bash" - AseN
  • @AlexeyTen I have and Bash and Dash. I do a launch via sh 1.sh url - Rajab
  • one
    @Radzhab so the default sh is dash . Run bash 1.sh ... , and better make the script executable and run ./1.sh ... - Alexey Ten
  • Do NOT use Bashism. On the one hand, life will be harder (well, the language is difficult because), but on the other hand, it is easier to handle. $((100*1024*1024)) than not arranged? - 0andriy

1 answer 1

The script is written for interpretation by the bash program.

You can use bash explicitly:

 $ bash файл_со_скриптом ссылка 

or by adding the executable bit to the file ( $ chmod u+x файл_со_скриптом ), implicitly (the path to the interpreter file will be taken from the first line of the script, decorated as shebang ):

 $ ./файл_со_скриптом ссылка 

The error message you receive indicates that the dash program was most likely called for interpretation. either explicitly:

 $ dash файл_со_скриптом ссылка файл_со_скриптом: 8: printf: Illegal option -v скачиваем файл_со_скриптом: 10: файл_со_скриптом: Illegal number: 100*1024*1024 

either implicitly (if you have /bin/sh is a link to /bin/dash ):

 $ sh файл_со_скриптом ссылка файл_со_скриптом: 8: printf: Illegal option -v скачиваем файл_со_скриптом: 10: файл_со_скриптом: Illegal number: 100*1024*1024 
  • You should not inspire people to use Bashism, then it only gets worse: ( - 0andriy