LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-27-2009, 11:08 AM   #1
agrestic
Member
 
Registered: Jan 2009
Location: atlanta, ga, usa
Distribution: sabayon 5, slack64, Lenny, LFS 6.4 user # 20665
Posts: 61

Rep: Reputation: 16
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.

Last edited by agrestic; 01-27-2009 at 11:25 AM.
 
Old 01-27-2009, 11:19 AM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,812
Blog Entries: 1

Rep: Reputation: 259Reputation: 259Reputation: 259
See if using the Boolean OR operator does what you want...
Code:
video=$(find $HOME/* -name *.flv -o -name *.mpg -o -name *.avi | sort)
 
Old 01-27-2009, 11:20 AM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,504

Rep: Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993
Beat me to it...

Last edited by TB0ne; 01-27-2009 at 11:21 AM.
 
Old 01-27-2009, 11:30 AM   #4
agrestic
Member
 
Registered: Jan 2009
Location: atlanta, ga, usa
Distribution: sabayon 5, slack64, Lenny, LFS 6.4 user # 20665
Posts: 61

Original Poster
Rep: Reputation: 16
Works perfectly.
Consequently, I just found a site explaining boolean -o.
Thanks weibullguy and TB0ne.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
about immediate and deferred variable assignment in GNU make George2 Programming 1 07-22-2011 05:55 PM
bash/sh: global or local variable with for (loop) isssue frenchn00b Programming 9 11-06-2008 07:24 AM
Java String variable re-assignment Cyhaxor Programming 9 11-24-2007 03:35 PM
Bash Local Variable Recursion With Array jshivers Programming 0 06-16-2006 04:31 PM
Trivial bash question - executing $COMMAND atom Programming 4 06-05-2005 04:17 AM


All times are GMT -5. The time now is 07:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration