Re: OT: Maildir vs. mh folders?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Ranjan,

Ranjan Maitra wrote:
> On Tue, 20 Oct 2020 18:11:23 -0500 Ranjan Maitra
> <maitra@xxxxxxxxx> wrote:
> 
>> Thanks, everybody, I am almost there. I am wondering how
>> do I get to list the files without the first two depths?
>> So, here is  a part of my code:
>>
>> MAILDIR=$HOME/Maildir
>> MHDIR=$HOME/mail
>> FOLDERSPre=$(find $MHDIR -type d -mindepth 1)
>>
>> So, then I get a list of directories:
>> /home/username/mail/....
>>
>> How do I get the /home/username out of it so that I can
>> append the rest to my Maildir directory?
>>
>> I guess this is now likely a bash question, and well and
>> truly OT. Luckily, every part of this thread is.
> 
> Sorry to answer my own question, but I managed to do this
> by using sed.

Nothing to be sorry about there.  You've answered your own
question, but also shared it with the list where others can
learn from it.  That's always a plus!

> I used:
> 
> for ff in $FOLDERSPre
> 
> f=$(echo "$ff" | sed -e 's/mail/Maildir/')
> 
> which is easier than what i was trying to do: remove the /home/username/mail out and replace with /home/username/Maildir.

Another way to slice this would be through parameter
expansion.  For example:

    for ff in $FOLDERSPre; do
        f=${ff/$MHDIR/$MAILDIR}
        ...
    done

In the bash manual, search for "Parameter Expansion" for
details on the various types of expansions available.  While
the speed of a parameter expansion versus a command
substitution (i.e., the $(echo $ff | sed ... ) in your
example) isn't likely to be noticeable in a script doing a
large MH to Maildir conversion, there are times when it can
improve a script's speed and/or system utilization.

Even without the small performance boost, using a parameter
expansion is often more concise and removes an external
command from the script.

The trade off is that if you're writing a script which needs
to be portable across a wide variety of different operating
systems, you need to consider whether you're using an
expansion that's supported by any POSIX shell (e.g. sh) or
is bash-specific (and ideally adjust the code and/or the
"#!" hashbang appropriately).

Of course, writing such scripts also involves knowing the
same of the utilities like sed, which can vary a good bit
between a GNU/Linux system, BSD-derivatives, Solaris, etc.

-- 
Todd

Attachment: signature.asc
Description: PGP signature

_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@xxxxxxxxxxxxxxxxxxxxxxx
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux