I am writing my first code in bash. I am stuck from 2 hours. This is my code:
#!/bin/bash declare -i l=0 declare -i d=0 declare -i s1=0 declare -i s2=0 declare -i t=0 declare -i o=0 declare -i p=0 for i in demo_room/subject_1/?* do if [ "${i:0:1}" = "l" ]; then ((l++)); echo "l=$l" python motempl_n.py $i $l elif [ "${i:0:1}" = "d" ]; then ((d++)); echo "d=$d" python motempl_n.py $i $d elif [ "${i:0:1}" = "o" ]; then o=$((o+1)); echo "o=$o" python motempl_n.py $i $o elif [ "${i:0:1}" = "p" ]; then p=$((p+1)); python motempl_n.py $i $p elif [ "${i:0:1}" = "t" ]; then t=$((t+1)); python motempl_n.py $i $t elif [ "${i:0:7}" = "slide_1" ]; then s1=$((s1+1)); python motempl_n.py $i $s1 #elif [ "${i:0:7}" == 'slide_2' ] else s2=$((s2+1)); python motempl_n.py $i $s2 fi done
So I am having a folder demo_room/subject_1
. In this folder I have 140 avi videos their names are:
20 videos have name: dislike_01
to dislike_20
20 videos have name: like_01
to like_20
20 videos have name: ok_01
to ok_20
20 videos have name: point_01
to point_20
20 videos have name: slide_1_01
to slide_1_20
20 videos have name: slide_2_01
to slide_2_20
20 videos have name: take_a_picture_01
to take_a_picture_1_20
What I want to do is first find the class of the input video then give its occurrence as input to python file. First 20 videos of subject_1
folder are dislike
one so this code works fine but the 21st video is like_01
but the parameter it passes to the python code is 21.
But it should be 1 because this is first video of like class in the for loop. And each time it prints value of $d
. It means each time it goes in 2nd if condition
. In the python code I can verify that the name of the video is like_01
but second value passed is 21
. Why? This happens for all the 140 videos.
;
's (all of them)echo
inside[ ... ]
must be a typo, right? Also, you're inconsistent in how you increment your counters.[ too many arguments