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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
ls -aR /home/$user/.thunderbird/$profile/ImapMail/ | grep -i $dir
In this case $dir=sent and so I get:
Code:
Sent.msf
Sent Mail
Sent Mail.msf
Sent-1
Sent-1.msf
Sent.msf
Sent Mail
Sent Mail.msf
Sent.msf
Sentry Telecom
Sentry Telecom.msf
Sentry Telecom
Sentry Telecom.msf
Sent
Sent.msf
I need to process the files that have no extensions, yes they are files, not directories. However the directory:
Code:
/home/$user/.thunderbird/$profile/ImapMail/
contains the following subdirectories:
Code:
imap.gmail.com
imap.gmail-1.com
In order to process the files I have to have the full path & filename, but all the HOWTOs I've looked at talk about "fullpath" in all other terms from what I need.
If you either know how to do this, or know the right HOWTO, please pass along the info, so I can finish my script.
But cannot process without the fullfilename that includes the fullpath, therefore the output file is always empty.
I have all this working in a hardcoded version, but other users will have directories unique to themselves, so attempting an autofinding version, that all TBird users can use.
get_IMdirs () {
#############################################################################
# Modified: Nyle Davis Mod Date: 17-04-25
# Purpose: Get all "ImapMail" subdirectories
# Vars:
#############################################################################
declare -a im_ray=();
declare -a im_dirs=();
imsub=${dir%:};
xx=0;
SAVEIFS=$IFS;
IFS=$(echo -en "\n\b");
im_dirs=$(ls -R $imsub);
for dir in ${im_dirs[@]}; do
imdir=${dir%:};
imfil=$(basename "$imdir");
imext="${imfil##*.}";
echo "P=> $imsub F=> $imfil E=> $imext";
if [[ "$imfil" == "$imext" ]]; then
im_ray[$xx]=${imsub}${imfil};
echo "IR=> ${imsub}${imdir}";
((xx=xx+1));
fi
done
IFS=$SAVEIFS;
} # end function get_IMdirs
where dir='/home/$user/.thunderbird/$profile/ImapMail/'
and has to have the ' for the special chars in the path, which becomes imsub.
Since the files being processed have no extension imfil and imext are an exact match, so processing to add to the array only happens then. However, when the array is to be processed later, that fullfilename, including the fullpath is needed or the file with never be found to process.
It was suggested I use the code:
Code:
basedir="/home/$user/.thunderbird/$profile/ImapMail/";
while IFS= read -rd '' path; do
echo "$path";
done < <(find "$basedir" -iname "${dir}*" -type f -print0)
and while that renders the path it also floods with unwanted information that then has to go through complex filtering to get back to just what is needed.
if there are spaces (in file/dir names) you ought to use "${var}" everywhere.
For example: imdir="${dir%:}";
the line imsub=${dir%:}; is unclear, dir is not (yet) initialized or ??? imfil=$(basename "$imdir"); can be written as: imfil="${imdir##*/}" for dir in ${im_dirs[@]}; do should be written as for dir in "${im_dirs[@]}"; do, but while is much better.
Quote:
while that renders the path it also floods with unwanted information that then has to go through complex filtering to get back to just what is needed.
would be nice to explain what is the problem exactly...
get_IMdirs () {
#############################################################################
# Modified: Nyle Davis Mod Date: 17-04-25
# Purpose: Get all "ImapMail" subdirectories
# Vars:
#############################################################################
declare -a im_ray=();
declare -a im_dirs=();
imsub=${dir%:};
xx=0;
SAVEIFS=$IFS;
IFS=$(echo -en "\n\b");
im_dirs=$(ls -R $imsub);
for dir in ${im_dirs[@]}; do
imdir=${dir%:};
while IFS= read -rd '' path; do
SAVEIFS=$IFS;
IFS=$(echo -en "\n\b");
imfil=$(basename "$imdir");
imext="${imfil##*.}";
IFS=$SAVEIFS;
if [[ "$imfil" == "$imext" ]]; then
basfil=$(basename "$path");
basext="${basfil##*.}";
if [[ "$basfil" == "$basext" ]]; then
echo "IF=> $imfil P=> $path";
im_ray[$xx]=$path;
((xx=xx+1));
fi
fi
done < <(find "$imsub" -iname "${imdir}*" -type f -print0)
done
IFS=$SAVEIFS;
} # end function get_IMdirs
you did not tell us anything about those error messages, so cannot help you to fix them.
from the other hand you can insert set -xv at the beginning of the function to see what's happening. Also you may try to use shellcheck to catch problems. www.shellcheck.net
find: warning: Unix filenames usually don't contain slashes (though pathnames do). That means that '-iname `/home/$user/.thunderbird/$profile/ImapMail/imap.gmail.com/filename.ext*'' will probably evaluate to false all the time on this system. You might find the '-wholename' test more useful, or perhaps '-samefile'. Alternatively, if you are using GNU grep, you could use 'find ... -print0 | grep -FzZ `/home/$user/.thunderbird/$profile/ImapMail/imap.gmail.com/filename.ext*''.
So I added the grep -FzZ and nothing improved.
I can't tell if my processing is right with so many errors as this loop over 14,000 times.
find: warning: Unix filenames usually don't contain slashes (though pathnames do). That means that '-iname ...' will probably evaluate to false all the time on this system.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.