You are not logged in.

#1 2012-05-01 06:40:53

chrisgray1497
Member
Registered: 2011-03-29
Posts: 12

bash script read input and feh

I was trying to make a quick script to organize some pictures using feh to display the picture in question and then using bash to read a character from the keyboard and move to a folder based on that letter. Problem is it opens every image in the folder at the start (which is overwhelming). I want to go image by image.

heres the simplified script. There would be different if statements for each letter/dir pair

#!/bin/bash

ls | while read file1; do        #while loop over all images in the dir

feh $file1 &                   
read ch1
if [[ $ch1 == "e" ]]
then
        mv $file1 /PATH/hawaii
        echo "moving to hawaii"
        pkill feh
fi

Problem seems to be that the script doesn't wait to receive the input $ch1 before moving on to the next iteration of the loop.  Except that when I do something simpler like the following it does seem to wait on the input

while
   echo '1'
   read ch1
   echo '2'
   echo '3'

Offline

#2 2012-05-01 08:09:32

moetunes
Member
From: A comfortable couch
Registered: 2010-10-09
Posts: 1,033

Re: bash script read input and feh

for f in *; do $(feh $f)&  read g; if [[ "$g" == "e" ]]; then mv -v $f ../tested; fi;pkill feh;  done;

waits for me to enter something before checking whether to move the image and closing the image and moving to the next.


You're just jealous because the voices only talk to me.

Offline

#3 2012-05-01 08:17:11

moetunes
Member
From: A comfortable couch
Registered: 2010-10-09
Posts: 1,033

Re: bash script read input and feh

So in a script it would be

#!/bin/bash
for f in *; do
    $(feh $f)&  read g
     if [[ "$g" == "e" ]]; then
          mv -v $f ../tested
     fi
     pkill feh
done
exit 0

indentations ftw


You're just jealous because the voices only talk to me.

Offline

#4 2012-05-01 08:43:12

chrisgray1497
Member
Registered: 2011-03-29
Posts: 12

Re: bash script read input and feh

awesome, thank you

Offline

Board footer

Powered by FluxBB