Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Didn't work for me. Here's my code if it helps... Thanks.
Code:
dir_list=`ls -ad */ 2>/dev/null`
cleaned_dirs=''
for dir_name in $dir_list ; do
cd $dir_name
# ... some stuff...
if [ $? ]; then
cleaned_dirs=${cleaned_dirs} ${dir_name}
fi
cd ..
done
has spaces around the +=, which is wrong. You cannot put spaces around an assigment operator in the shell. Bash doesn't understand += anyway (some shells do though).
Code:
string1=${string1} ${string2}
fails for the same reason, a space between string1 and string2 (this tries to run the command $string2). It should be
Code:
string1="${string1} ${string2}"
But, as I said, you should be using an array for this purpose (a list of seperate directories).
the array may not really be necessary if he is only building this list in order to pass it as the arguments to a command. Then an array may only complicate the things. This scenario isn't unlikely in a shell script.
To the OP, dawkcid caught my mistake at the same time I did, but you should use the code in my post, as dakwcid's concatenates the strings without a space in between them.
the array may not really be necessary if he is only building this list in order to pass it as the arguments to a command. Then an array may only complicate the things. This scenario isn't unlikely in a shell script.
Oh, I was assuming it was intended just for logging/reporting which directories had been processed. So, yeah, a string may be preferable depending on what you want to do with it.
Quote:
To the OP, dawkcid caught my mistake at the same time I did, but you should use the code in my post, as dakwcid's concatenates the strings without a space in between them.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.