#!/bin/bash # http://en.wikipedia.org/wiki/European_Article_Number oe="13" while read line; do for (( j=0; j<${#line}; j++ )); do chk=$((chk+${line:$j:1}*${oe:$j%2:1})) done [[ $((chk%10)) == 0 ]] && digit=0 || digit=$((10-chk%10)) chk=0 echo ${line}${digit} done