LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 02-21-2011, 05:13 PM   #16
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107

Quote:
Originally Posted by nass View Post
I would expect that the above construct would fill in the variable FOLDER_LIST with a list of folders from the current directory.
Will this work?
Code:
#!/bin/bash
pushd /usr/share/doc

FOLDER_LIST=( $(ls -dAl * | grep -v "^l" | awk '{ print $8 }') )
for (( INDEX = 0 ; INDEX < ${#FOLDER_LIST[@]} ; INDEX++ )) ; do
    echo "FOLDER_LIST[$INDEX] = ${FOLDER_LIST[$INDEX]}"
done

popd
The idea for the array code came directly from the Linux Documentation Project pages for bash.
 
1 members found this post helpful.
Old 02-21-2011, 05:20 PM   #17
nass
Member
 
Registered: Apr 2006
Location: Athens, Greece
Distribution: slackware, debian, ubuntu
Posts: 666

Original Poster
Rep: Reputation: 39
tried GazL but...

Quote:
./users2: line 15: syntax error near unexpected token `<'
./users2: line 15: `done < < ( ls -d $PWD | grep -v "lost+found" )'
[/share/MD0_DATA] #
did you intentionally leave a gap between the 2 redirects? < < ??

and also if you run the script like that, on the 1st pass of the while loop, what will be the value of the $directory?
(should i safely assume that the statement next to the 'done' while loop will be run in order to give a value to the $directory?)
 
Old 02-21-2011, 05:29 PM   #18
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
Quote:
Originally Posted by nass View Post
tried GazL but...



did you intentionally leave a gap between the 2 redirects? < < ??

and also if you run the script like that, on the 1st pass of the while loop, what will be the value of the $directory?
(should i safely assume that the statement next to the 'done' while loop will be run in order to give a value to the $directory?)
Yes the space is intentional. < <( command ) is a bash specific way of doing a command | while read ....
Bash starts pipelines in subshells where as traditional shells don't and that can cause problems with referencing variables sometimes.

It's possible that your shell isn't bash but is sh instead in which case my examples wont work as sh doesn't support the < <( command ) syntax.
But back at the very beginning you said it was a bash script, so that's what I wrote.
 
1 members found this post helpful.
Old 02-21-2011, 07:04 PM   #19
nass
Member
 
Registered: Apr 2006
Location: Athens, Greece
Distribution: slackware, debian, ubuntu
Posts: 666

Original Poster
Rep: Reputation: 39
indeed GazL, the busybox is running sh rather than bash - i only now realise too.

In the end I set aside the idea of lists. I was looking for lists thinking that they are more dynamic. But then again in bash arrays are dynamic too. so no reason to look for lists (too much C programming I guess).

here is what I have, using arrays in the end (as David1357 suggested)...


Code:
#!/bin/sh

USERS_DIR="/share/MD0_DATA/"
cd $USERS_DIR

FOLDER_LIST=( $( ls -d1 * | grep -v "\*$" ) )
#echo "FOLDER_LIST items = ${#FOLDER_LIST[@]}"
#echo "FOLDER LIST wc = " `ls -dA1 * | wc -l`

USERS_LIST=( $( cat /etc/passwd | cut -d":" -f1 ) )
#echo "USERS_LIST items = ${#USERS_LIST[@]}"


for (( INDEX = 0 ; INDEX < ${#FOLDER_LIST[@]} ; INDEX++ )) ; do
    echo "FOLDER_LIST[$INDEX]=${FOLDER_LIST[$INDEX]}"
    for (( i = 0 ; i < ${#USERS_LIST[@]} ; i++ )) ; do
        echo "USERS_LIST[$i]=${USERS_LIST[$i]}"
        if [[ "${FOLDER_LIST[$INDEX]}" == "${USERS_LIST[$i]}" ]] ; then
            echo "found a match ${FOLDER_LIST[$INDEX]} is matched to ${USERS_LIST[$i]}"
        fi
    done
done
the two lists are working 'fine'. as in the array cells get filed up almost as expected (exception: in FOLDER_LIST the 'network recycle bin' folder is perceived as 3 different elements but its OK for now.)

thank you all for your help
Goodnight
 
  


Reply



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
unixODBC could not construct a property list for (SQLITE) lhorace Linux - Newbie 3 12-17-2009 12:07 AM
How to generate a list of MD5 checksums? General Linux - Software 2 06-10-2006 09:59 PM
generate the update list sunhui Linux - Software 1 02-20-2006 05:56 PM
generate the update list sunhui Linux - Software 0 02-17-2006 04:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 01:38 PM.

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
Open Source Consulting | Domain Registration