9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Romano <me+unobe@fallglow.com>
To: 9front@9front.org
Subject: Re: [9front] Re: /bin/"" use of rc -c instead of eval
Date: Fri, 05 Jul 2024 18:48:11 -0700	[thread overview]
Message-ID: <0FA3013289FC138D02F16A45F7F68FDA@smtp.pobox.com> (raw)
In-Reply-To: <ZoiGijN5LTEkXSRK@alice>

On Fri Jul  5 16:52:25 -0700 2024, ality@pbrane.org wrote:
> Romano <me+unobe@fallglow.com> once said:
> > I use " and "" to review previous commands and execute them, and
> > I was puzzled when a previous 'cd' command didn't work. I
> > suspected it might be perhaps to 'cd' being a built-in, and
> > looking at the source code for "" my suspicion was confirmed. The
> > last line that executes the command is: rc -c $"_x
> >
> > Any reason why this isn't using eval instead so that rc built-ins
> > work (eval $"_x)
> 
> Did you try it? What happened?
> 
> Hint: what you seem to want is not
> 
> 	"" cd.*foo
> 
> but
> 	. <{" cd.*foo}
> 

Thanks, Anthony, even eval won't work for what I want. I had lazily
just tested:
  rc -c 'cd /sys/src'
against:
  eval 'cd /sys/src'

The above eval works if run directly, but not when within a shell
script like "", so I'd have to think of some other way. 

One way that looks promising is defining "" as a function with
the source of "" and changing 'rc -c' to 'eval':

cpu% whatis ""
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% pwd
/
cpu% "" cd /sys
	 cpu% cd /sys/src
cpu% pwd
/sys/src
cpu%


  reply	other threads:[~2024-07-06  1:49 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 [this message]
2024-07-06  8:00     ` sirjofri
2024-07-06  9:41       ` Romano
2024-07-06 14:05         ` sirjofri
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=0FA3013289FC138D02F16A45F7F68FDA@smtp.pobox.com \
    --to=me+unobe@fallglow.com \
    --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).