From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id C5C1628584 for ; Wed, 22 May 2024 03:49:27 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1716342567; b=gIUOR3YPEYqewQPgJLrYhe6kGNEmxfneROGMjrNDE9QDP8RLdqiDNzIWHglUrswdwvDAgLoDV9 Wh21oNbr9NacHmSGEbQPcjJisGTiH0JDnhsRT8iWTLC4S5RWNaVcuj0D3nPqQ3lqrReO4KWkH5 ZYGsqeGeFUxKadimysRBEZT/7H9zBuCDrVdfJCk5hyr4pb0KfDq1CwgGDxiZ1HLDOi4wDkppCq iXJ3YsKPEK+dkS7UEk7uTp0etmRDjFL5cM5uR4a/LxKuLzdcF7xJ+DleHOb/akmP5Z4ogGBHqK vI5+EKyMBhXEMVkYYxd3SS6VtTFEX4N7NiKzIPeO+AM9rg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lj1-f180.google.com) smtp.remote-ip=209.85.208.180; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1716342567; bh=CL89l90ZXangvRvKHMvUS+z2gaoi5bN5Yt8hDpgdspo=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=D0j8gKNDNwS+Tq0qa0a0DOKi1k3qt4Hfyvq0SDCmy71qnKa2P54fQPCpRCUKnR1KbNmcF1sgn8 kSSr8G9RUGcneMf6Ju5leFrgTQp2HBGgQt8R3dvGt/Wdedtn+TWuolD2MrdmyWokKsi5xH3Rc3 WFWHVZ7qvfHYTmYuGc5QfvSymQfKCQ1EspTRUebFwpOLhZ46HsErjf3MrauoSCIlN14lphgHoO cEznxm+JI4Ikv7bZAZN2Eru7aaoMhhoATDxcrQSL3tk2ZMHBdX5l8cGUUxA/SXgY2rSXhhML3a lIrguIsjl2KXfUdyJahA1IoGJD2DT7UE43YC0Dd1PCt98w==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=sH2QPz9FQBBfy+vejntGhGgbOGKmB0YY5ybxiyXcBN4=; b=DP379HlQxTRN85AyD2EuczH01w 7auYalyDuQaRd/iOLXrz1OCHxQ55lGqrAOFdPAX77HISxRmLWCAT2fZvJYrGYD7rd5xLi5vEhOqZk aY6i/ok6KO0NyyvljHuBtALI4N2u740zOK9GtlSS8TEkoNTwAHVqfWJso/j2A7NZaKo6XJV6WBH7l zzT681ZaF/tBYUVXPX0Rl8PIGEstLzP/NmykU3gCkiX99cyR01X2tiptIbdhta5nhsvGUOEhnxb9R 7gUgnVYueo//TybK9gvQZGI0lbL4dAzkdtbvHPgJrmO1mVNcUfNiDGHFsiWK5Y4kApx11eGcvVzpl Z5FR974w==; Received: by zero.zsh.org with local id 1s9b6c-00053R-Du; Wed, 22 May 2024 01:49:26 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lj1-f180.google.com) smtp.remote-ip=209.85.208.180; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lj1-f180.google.com ([209.85.208.180]:59825) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1s9b60-0004Mc-2g; Wed, 22 May 2024 01:48:49 +0000 Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2e724bc466fso36598281fa.3 for ; Tue, 21 May 2024 18:48:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716342527; x=1716947327; darn=zsh.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=sH2QPz9FQBBfy+vejntGhGgbOGKmB0YY5ybxiyXcBN4=; b=g41+6L6cN78mRReaRlNgv6dgRosgC63TYi08b7+K8DXu7wRsB+Pwn+u6EHOa5YqbvV cfo8eKadrsZG8DTrUtYiSOTQ5RUZ29EWxTNxEYhIepQJEGAKVR7zajOcaTQZHv+h9xoT ofSjaXPcyNF5O2kAjpKbbDhfr+QLX8Q1ltOzreY+Z4o/LQJ4Ztrs0cDBgJsrsaN7imso ExbY/cVcmdAfB9wV29nZgRSQVcgWocpsLqApWYHss/SFgMF0QarTa5P4TssIjdf56BoG cQAb9rxfHkR29SgrOjZO3W93QZq+baflDu3oh/6T8p6P5NhNFQ7NelZtHH9CS6xIB0op SGjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716342527; x=1716947327; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=sH2QPz9FQBBfy+vejntGhGgbOGKmB0YY5ybxiyXcBN4=; b=HXVgsYoFQdr7P3hjCYjstv4DAauEOa0GLBZCjNo2UaHJ9k3KM4yqk732HKzVgAcaEe WiY7WrgMvpA63SboEYOSlF/tlfGQfofJTyuEp8t1hH4ApmoEmd4WfLP2MjoCI6SF8kq7 1amXiQwe1vXZrXYIXN364935IhHvpYXMbxc1IM4fEKdwf7opKz2Lhy8bfKdAurzccjUc BpmICQ6wZ3MskY0KA/fYy3HCHeCOK6kpHeHiqTjx7w+8jWZh5j2OSMZoEntf3MXUwnjH jc8ynsEqsX+53Rkoma/gnvoKJqG/CcRYZS6UFPOx2KR8+2DwD8k0VXBFB3QR2DudCPsS FNJw== X-Gm-Message-State: AOJu0Ywv8VvhGl94OpRU7MC4gck18c8tEWww8ecccgqkTXWVH7fEfHoF 0QU1YEpEvq6nlhYh507IcJ+Xqc1e0nYXrgPA62zV2Sb6RS4njZgWmJCFW1lGGERMPY/XJsVEppU sxTNam+rs5j5pSloCxF+2JxZhiN4= X-Google-Smtp-Source: AGHT+IGavxYu+M5GMYLGTK9WcKGVw1Uaa7osDYfoIpuEgpH3R5bmETaQdOx1zynz2ITeEZ1+xuiyeO+ZPytBKtgGX0M= X-Received: by 2002:a2e:9852:0:b0:2e5:2181:7bd5 with SMTP id 38308e7fff4ca-2e94959c72bmr4526281fa.35.1716342526805; Tue, 21 May 2024 18:48:46 -0700 (PDT) MIME-Version: 1.0 References: <75784205-3d78-4dd8-8474-e2eb48598307@eastlink.ca> In-Reply-To: <75784205-3d78-4dd8-8474-e2eb48598307@eastlink.ca> From: "Mark J. Reed" Date: Tue, 21 May 2024 21:48:34 -0400 Message-ID: Subject: Re: the splits To: Ray Andrews Cc: Zsh Users Content-Type: multipart/alternative; boundary="0000000000009f90570619012252" X-Seq: 29962 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: --0000000000009f90570619012252 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=E2=80=AFPM Ray Andrews 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 i= t > one of these programs:?\n(Please wait or press '^C' to quit.)" > > abc=3D$(lsof | grep $mountpoint) > abc=3D( ${(f)abc} ) > for def in $abc[@]; do ghi=3D( ${=3Ddef} ); 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 thes= e > 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=3D$(lsof | grep $mountpoint) > abc=3D( ${(f)abc} ) > for def in $abc[@]; do ghi=3D( ${=3Ddef} ); 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 ca= n > do all of the above in 20 characters. > > > --=20 Mark J. Reed --0000000000009f90570619012252 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Running=C2=A0lsof | grep=C2=A0seems a bit si= lly. Can't you just do lsof $mountpoint?

When= I want to select columns I usually reach for awk:

=C2= =A0sudo 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=E2=80=AFPM Ray Andrews <rayandrews@eastlink.ca> wrote:
=20 =20 =20
A function of mine might need to unmount someting.=C2=A0 If there's a problem I try to be helpful:


umount -v "$mountpoint" ||
{
=C2=A0=C2=A0=C2=A0 # Helpful diagnostics if partition won't unmou= nt:
=C2=A0=C2=A0=C2=A0 echo "\nCan't unmount $mountpoint.=C2=A0 = Is a terminal logged on?=C2=A0 Or is it one of these programs:?\n(Please wait or press '^C' = to quit.)"

=C2=A0=C2=A0=C2=A0 abc=3D$(lsof | grep $mountpoint)
=C2=A0=C2=A0=C2=A0 abc=3D( ${(f)abc} )
=C2=A0=C2=A0=C2=A0 for def in $abc[@]; do ghi=3D( ${=3Ddef} ); print = -- "$ghi[1]\t$ghi[-1]\n"; done
=C2=A0=C2=A0=C2=A0 return
}=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0

Typical run:


% mnt ,U sda

Unmounting partitions ...
umount: /mnt/sda/1: target is busy.

Can't unmount /mnt/sda/1.=C2=A0 Is = a terminal logged on?=C2=A0 Or is it one of these programs:?
(Please wait or press '^C' to quit.)

zsh=C2=A0=C2=A0=C2=A0 =C2=A0 /mnt/sda/1/EFI/BO= OT
geany=C2=A0=C2=A0=C2=A0 /mnt/sda/1/EFI/BOOT
geany=C2=A0=C2=A0=C2=A0 /mnt/sda/1/EFI/BOOT
geany=C2=A0=C2=A0=C2=A0 /mnt/sda/1/EFI/BOOT

----------------------------------------------------

... works fine but I'll bet:

abc=3D$(lsof | grep $mountpoint)
abc=3D( ${(f)abc} )
for def in $abc[@]; do ghi=3D( ${=3Ddef} ); print -- "$ghi[1]\t$ghi[-1]\n"; done


... is belabored.=C2=A0=C2=A0 Can that be streamlined?=C2=A0 As alway= s my splitting is a problem.=C2=A0 I need to process line by line, but the= n word by word so as to grab just the first and last words from 'lsof' output.=C2=A0 I'll bet Roman can do all of the abo= ve in 20 characters.




--
Ma= rk J. Reed <mar= kjreed@gmail.com>
--0000000000009f90570619012252--