From: "Mark J. Reed" <markjreed@gmail.com>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: the splits
Date: Tue, 21 May 2024 21:48:34 -0400 [thread overview]
Message-ID: <CAA=-s3ySNN2WkFoi5q3zzGkwpWhv7cUP6CPKx=nKTypjBn6uSA@mail.gmail.com> (raw)
In-Reply-To: <75784205-3d78-4dd8-8474-e2eb48598307@eastlink.ca>
[-- Attachment #1: Type: text/plain, Size: 1829 bytes --]
Running *lsof* *| grep* seems a bit silly. Can't you just do *lsof
$mountpoint*?
When I want to select columns I usually reach for *awk*:
*sudo lsof $mountpoint | awk '{print $1, $NF}'*
No need to read all text into a variable when you can just send it straight
to the screen.
On Tue, May 21, 2024 at 1:43 PM Ray Andrews <rayandrews@eastlink.ca> wrote:
> A function of mine might need to unmount someting. If there's a problem I
> try to be helpful:
>
>
> umount -v "$mountpoint" ||
> {
> # Helpful diagnostics if partition won't unmount:
> echo "\nCan't unmount $mountpoint. Is a terminal logged on? Or is it
> one of these programs:?\n(Please wait or press '^C' to quit.)"
>
> abc=$(lsof | grep $mountpoint)
> abc=( ${(f)abc} )
> for def in $abc[@]; do ghi=( ${=def} ); print --
> "$ghi[1]\t$ghi[-1]\n"; done
> return
> }
>
> Typical run:
>
>
> % mnt ,U sda
>
> Unmounting partitions ...
> umount: /mnt/sda/1: target is busy.
>
> Can't unmount /mnt/sda/1. Is a terminal logged on? Or is it one of these
> programs:?
> (Please wait or press '^C' to quit.)
>
> zsh /mnt/sda/1/EFI/BOOT
> geany /mnt/sda/1/EFI/BOOT
> geany /mnt/sda/1/EFI/BOOT
> geany /mnt/sda/1/EFI/BOOT
>
> ----------------------------------------------------
>
> ... works fine but I'll bet:
>
> abc=$(lsof | grep $mountpoint)
> abc=( ${(f)abc} )
> for def in $abc[@]; do ghi=( ${=def} ); print -- "$ghi[1]\t$ghi[-1]\n";
> done
>
> ... is belabored. Can that be streamlined? As always my splitting is a
> problem. I need to process line by line, but then word by word so as to
> grab just the first and last words from 'lsof' output. I'll bet Roman can
> do all of the above in 20 characters.
>
>
>
--
Mark J. Reed <markjreed@gmail.com>
[-- Attachment #2: Type: text/html, Size: 3290 bytes --]
next prev parent reply other threads:[~2024-05-22 1:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-21 17:42 Ray Andrews
2024-05-22 1:48 ` Mark J. Reed [this message]
2024-05-22 2:21 ` Ray Andrews
2024-05-22 5:56 ` Roman Perepelitsa
2024-05-22 19:25 ` Ray Andrews
2024-05-22 20:41 ` Lawrence Velázquez
2024-05-22 21:36 ` Ray Andrews
2024-05-23 0:04 ` Lawrence Velázquez
2024-05-23 0:30 ` Ray Andrews
2024-05-23 2:31 ` Mark J. Reed
2024-05-23 12:58 ` Ray Andrews
2024-05-22 5:57 ` Jim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAA=-s3ySNN2WkFoi5q3zzGkwpWhv7cUP6CPKx=nKTypjBn6uSA@mail.gmail.com' \
--to=markjreed@gmail.com \
--cc=rayandrews@eastlink.ca \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).