[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] Vælg tilfældig fil i Bash



Leo Laursen <sslug@sslug>:

> Her er et lidt kluntet forslag.
> #!/bin/sh

> files=($(find . -type f -print0 | xargs -0))
> echo ${files[$RANDOM % ${#files}]#*/}

Hmmn. dårligt forslag. Jeg blev snydt af at ${#files} syntes at være
korrekt; men vi er tilbage til at sh skiller på mellemrum.(space tab
newline)

Det virker vist rimeligt hvis IFS sættes til kun newline
#v+
#!/bin/sh
IFS='
'
array=($(find . -type f))
echo ${array[$RANDOM % ${#array}]#./}
#v-

Leo
-- 
When a man knows he is to be hanged in a fortnight, it concentrates his
mind wonderfully.
		-- Samuel Johnson


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:43 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *