I have the following script:
#!/bin/bash
y=$(ls -t ./pics/0/*.png | head -n 2 | tail -n 1)
new=$(ls -t ./pics/0/*.png | head -n 1)
while true
do
if cmp --silent "$y" "$new" ; then
y=$(ls -t ./pics/0/*.png | head -n 1)
base64 $y | tr -d '\n' | sed '$ a \'
new=$(ls -t ./pics/0/*.png | head -n 1)
fi
done
What am I doing wrong? To be clear my goal is to compare whether the newest file is different from the previous newest file and only if it is generate a unique BASE64 to STDOUT (meaning it should be printed only ONCE).
if
. It isif [ cmp --silent $y $new != null ]
. – schrodingerscatcuriosity Aug 19 '19 at 19:21then
. – schrodingerscatcuriosity Aug 19 '19 at 21:35$x -le 5
You don't have in your code an update of thex
value. The expression is always true, which makes it an infinite loop. – schrodingerscatcuriosity Aug 19 '19 at 21:44y=0
) with a list of files ($new). this won't work.cmp
takes exactly two filename arguments. 0 is probably not a filename, and $new can contain 0, 1, or any number of filenames. – cas Aug 20 '19 at 01:01y="$(ls -t ./pics/0/*.png | head -n 2 | tail -n 1)"
andnew="$(ls -t ./pics/0/*.png | head -n 1)"
. i have no idea what the rest of your script is meant to do because it makes little or no sense. – cas Aug 20 '19 at 01:03[ -z "$(cmp ...)" ]
? You want to test the exit code fromcmp
, not its output (which is typically empty). Useif cmp "$y" "$new" ; then
instead. – cas Aug 20 '19 at 10:15while true; do ........ ; done
. Testing for[ $x -le 5 ]
just makes it look like you forgot to increment $x. – cas Aug 20 '19 at 10:17| tr -d '\n' | sed '$ a \'
does: it's for formatting the message, it first removes all newlines if there are any and puts one at the end. – Sir Muffington Aug 20 '19 at 12:07