[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: bash syntax



Am 29. Jul, 2021 schwätzte mick crane so:

moin moin nick,

I nicked this off some guy on the internet.
 1 #!/bin/bash
 2 count_file="scan_count.txt"
 3 ct=`cat $count_file`
 4 ((ct++))
 5 scanimage > /home/mick/DATA/SCANS/scan-$ct.pnm
 6 echo $ct > $count_file

What's the thing with the ct being in double brackets and not having the "$" ?

shell math.

Seach the bash man page for "ARITHMETIC EVALUATION"

In this case, it's adding one to the value that ct had.

3 Read the number in the file
4 Increment it by one
5 Run scanimage using the number in the file name
6 Write the new number to the file

scan_count.txt just is one line with a number.

It's tracking the number of iterations to create numbered filenames for
the scanimage output.

ciao,

der.hans
--
#  https://www.LuftHans.com   https://www.PhxLinux.org
#  When I work, I work hard. When I play, I play hard.
#  When I sit, I sleep. - Embe Kugler

Reply to: