LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   trivial: bash, local variable assignment (https://www.linuxquestions.org/questions/linux-newbie-8/trivial-bash-local-variable-assignment-700248/)

agrestic 01-27-2009 11:08 AM

trivial: bash, local variable assignment
 
I made a short script to help me learn bash. The function in question is:
Code:

watchVideo()        {
# Create alphabetical array of video files by recursively scanning $HOME.
video=$(find $HOME/* -name *.flv |sort; find $HOME/* -name *.mpg |sort; find $HOME/* -name *.avi |sort)
PS3=">>> Choose; hit Enter. > "
echo ""
echo " 0) Return to Main Menu."
# Display all video files.
select choice2 in $video
do
    if [ $choice2 ==0 ]; then
        hello # If $USER chooses 0, return to Main Menu.
    else :
        exec mplayer $choice2
        break
    fi
done

exit 0
}

I just want 1 command for the video variable: find's -name parameter accepting a list of filenames prefaced with * instead of the same command 3 times. I've tried
Code:

find $HOME/* -name [*.mpg,*.flv,*.avi] | sort
and many variations, but to no avail. How can this be done? BTW, this is on Ubuntu 8.10.

*****
Update: I tried "find -name $HOME/*/[*.mpg, *.flv, *.avi] | sort" which gave:
Code:

find: warning: Unix filenames usually don't contain slashes (though pathnames do).  That means that '-name `/home/agrestic/*/[*.mpg,'' will probably evaluate to false all the time on this system.  You might find the '-wholename' test more useful, or perhaps '-samefile'.
And "find -wholename $HOME/*/[*.mpg, *.flv, *.avi] | sort" which gives:
Code:

find: paths must precede expression: *.flv,
So still no clue. :)

TIA.

weibullguy 01-27-2009 11:19 AM

See if using the Boolean OR operator does what you want...
Code:

video=$(find $HOME/* -name *.flv -o -name *.mpg -o -name *.avi | sort)

TB0ne 01-27-2009 11:20 AM

Beat me to it...:)

agrestic 01-27-2009 11:30 AM

Works perfectly. :D
Consequently, I just found a site explaining boolean -o.
Thanks weibullguy and TB0ne.


All times are GMT -5. The time now is 10:13 AM.