From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <9front-bounces@9front.inri.net> X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI autolearn=ham autolearn_force=no version=3.4.4 Received: from 9front.inri.net (9front.inri.net [168.235.81.73]) by inbox.vuxu.org (Postfix) with ESMTP id 2372223E88 for ; Sat, 6 Jul 2024 16:08:30 +0200 (CEST) Received: from sirjofri.de ([5.45.105.127]) by 9front; Sat Jul 6 10:05:18 -0400 2024 Received: from dummy.faircode.eu ([95.90.217.91]) by sirjofri.de; Sat Jul 6 16:05:09 +0200 2024 Date: Sat, 6 Jul 2024 16:05:06 +0200 (GMT+02:00) From: sirjofri To: 9front@9front.org Message-ID: <6fdf85e1-93f4-4e54-80e5-77ee4d0d8f1f@sirjofri.de> In-Reply-To: <9B97890FFC11EBEF9081B4D16E0DB78D@smtp.pobox.com> References: <9B97890FFC11EBEF9081B4D16E0DB78D@smtp.pobox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Correlation-ID: <6fdf85e1-93f4-4e54-80e5-77ee4d0d8f1f@sirjofri.de> List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: element out-scaling-oriented database Subject: Re: [9front] Re: /bin/"" use of rc -c instead of eval Reply-To: 9front@9front.org Precedence: bulk 06.07.2024 11:43:32 Romano : > Maybe I did not give enough context in my reply: I know > that " lists *previous* commands and "" executes them. So > 'cd /sys/src' was something I had previously run in that > window. Here's a comparison of the current "" functionality: > > |cpu% cd /sys/src > |cpu% cd /sys > |cpu% pwd > |/sys > |cpu% " cd > |=C2=A0=C2=A0 cpu% cd /sys/src > |=C2=A0=C2=A0 cpu% cd /sys > |cpu% "" cd.*src > |=C2=A0=C2=A0=C2=A0 cpu% cd /sys/src > |cpu% pwd > |/sys > |cpu% > > And here it is using "" as a fn with eval: > > |cpu% fn "" { > |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 PROMPT=3D'[^=C2=A0 ]*(%|;)+[=C2=A0= =C2=A0 ]+' > |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 _x=3D`{ > |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 " $*|tail -= 1 > |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if(~ $#_x 0){ > |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 >[1=3D2]ech= o no such command found > |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 exit notfou= nd > |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 >[1=3D2]echo '=C2=A0=C2=A0=C2=A0 ' = $_x > |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 _x=3D`{ > |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 echo -n 'ev= al '''; echo $_x|sed 's/^'^$PROMPT^'//; s/''/''''/g; s/$/''/' > |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 eval $"_x > |=C2=A0=C2=A0 } > |cpu% cd /sys/src > |cpu% cd /sys > |cpu% pwd > |/sys > |cpu% " cd > |=C2=A0=C2=A0 cpu% cd /sys/src > |=C2=A0=C2=A0 cpu% cd /sys > |cpu% "" cd.*src > |=C2=A0=C2=A0=C2=A0 cpu% cd /sys/src > |cpu% pwd > |/sys/src > |cpu% > > Did you think I was saying it worked differently? Initially, it sounded like that, but with that context you're right. > My main point is that built-in rc commands don't > like other commands with "". That is, even tho' > it'll happily print out the cd command, it has > no effect in the shell since it's run in a > subshell. The most I could do is then copy-and- > paste if I wanted to use it. AFAICT a handful > would really make a difference with the fn-form > of "": cd, eval, flag, fn, and '.'. I don't think this has much to do with builtins or not, but with the subshe= ll. Cd is changing "the namespace". I wonder how "" works with mounts/binds= : do they also only change the namespace of the subshell? I'd guess they do= . >> Note that I never tested cd'ing with "", which means a lot. It's probabl= y not as useful in most cases, which makes sense if you think about it: you= use cd to switch to another directory. When you're there, running it again= is a no-op at best, or it fails. > > Switching back and forth between different directories > is a common occurrence during development for me, so > I wanted something akin to bash-like 'cd -' or '^R cd' > without having to use the mouse. I usually have a single rc command at the end of my test scripts (or I run = it manually). That way I can investigate/analyze the results, and just use = ^D to fall back to my main shell. Sure that's not ideal for everyone, but w= hen I call a program I wouldn't expect it to change my directory at all. I often have a ramfs behind an rfork n, so I build my test scripts like thi= s: > #!/bin/rc > rfork en > ramfs > # test... > cd /tmp > rc sirjofri