From: sirjofri <sirjofri+ml-9front@sirjofri.de>
To: 9front@9front.org
Subject: Re: [9front] Re: /bin/"" use of rc -c instead of eval
Date: Sat, 6 Jul 2024 16:05:06 +0200 (GMT+02:00) [thread overview]
Message-ID: <6fdf85e1-93f4-4e54-80e5-77ee4d0d8f1f@sirjofri.de> (raw)
In-Reply-To: <9B97890FFC11EBEF9081B4D16E0DB78D@smtp.pobox.com>
06.07.2024 11:43:32 Romano <me+unobe@fallglow.com>:
> 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
> | cpu% cd /sys/src
> | cpu% cd /sys
> |cpu% "" cd.*src
> | cpu% cd /sys/src
> |cpu% pwd
> |/sys
> |cpu%
>
> And here it is using "" as a fn with eval:
>
> |cpu% fn "" {
> | PROMPT='[^ ]*(%|;)+[ ]+'
> | _x=`{
> | " $*|tail -1
> | }
> | if(~ $#_x 0){
> | >[1=2]echo no such command found
> | exit notfound
> | }
> | >[1=2]echo ' ' $_x
> | _x=`{
> | echo -n 'eval '''; echo $_x|sed 's/^'^$PROMPT^'//; s/''/''''/g; s/$/''/'
> | }
> | eval $"_x
> | }
> |cpu% cd /sys/src
> |cpu% cd /sys
> |cpu% pwd
> |/sys
> |cpu% " cd
> | cpu% cd /sys/src
> | cpu% cd /sys
> |cpu% "" cd.*src
> | 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 subshell. 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 probably 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 when 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 this:
> #!/bin/rc
> rfork en
> ramfs
> # test...
> cd /tmp
> rc
sirjofri
next prev parent reply other threads:[~2024-07-06 14:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-05 22:23 [9front] " Romano
2024-07-05 23:14 ` Stanley Lieber
2024-07-05 23:49 ` [9front] " Anthony Martin
2024-07-06 1:48 ` Romano
2024-07-06 8:00 ` sirjofri
2024-07-06 9:41 ` Romano
2024-07-06 14:05 ` sirjofri [this message]
2024-07-06 14:08 ` sirjofri
2024-07-11 6:02 ` Romano
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=6fdf85e1-93f4-4e54-80e5-77ee4d0d8f1f@sirjofri.de \
--to=sirjofri+ml-9front@sirjofri.de \
--cc=9front@9front.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.
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).