• [ksh93] defunct 'fc' command?

    From Janis Papanagnou@21:1/5 to All on Mon Jul 1 11:03:17 2024
    In a recent thread about an emacs mode editing mode function in ksh
    there was a note about ^O ("it will stay in the history and move to
    the next line"). Thinking about an emulation in vi editing mode I
    noticed that 'fc' doesn't seem to work on my Limux platform (neither
    with ksh93u+ nor with ksh93u+m). Usually I use that built-in command
    only as 'fc -l' (to list the history entries), and omitting the '-l'
    should execute these commands. Alas, 'fc <from> <to>' doesn't work;
    for example

    $ fc -l 1013 1015
    1013 ls X
    1014 ls Y
    1015 ls Z
    $ fc 1013 1015
    15
    ^C
    ?
    ^Z[1] + Stopped fc 1013 1015
    $ kill %%
    [1] + Terminated fc 1013 1015


    Is that an issue in my environment (or on my platform), or a bug?

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Geoff Clare@21:1/5 to Janis Papanagnou on Mon Jul 1 14:00:13 2024
    Janis Papanagnou wrote:

    I noticed that 'fc' doesn't seem to work on my Limux platform (neither
    with ksh93u+ nor with ksh93u+m). Usually I use that built-in command
    only as 'fc -l' (to list the history entries), and omitting the '-l'
    should execute these commands. Alas, 'fc <from> <to>' doesn't work;
    for example

    $ fc -l 1013 1015
    1013 ls X
    1014 ls Y
    1015 ls Z
    $ fc 1013 1015
    15
    ^C
    ?
    ^Z[1] + Stopped fc 1013 1015
    $ kill %%
    [1] + Terminated fc 1013 1015


    Is that an issue in my environment (or on my platform), or a bug?

    It's an issue with your expectation. By default, fc starts an editor. Presumably you don't have FCEDIT set, as your output shows the default
    editor (ed) was used; it was ed that wrote the "15" and the "?".

    If you just want the commands executed, you can specify an editor
    that does nothing:

    fc -e true 1013 1015
    fc -e : 1013 1015

    Or, if you only want to execute one command, you can use -s (without
    specifying a substitution).

    This is all POSIX standard stuff.

    --
    Geoff Clare <netnews@gclare.org.uk>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Geoff Clare on Mon Jul 1 17:54:18 2024
    On 01.07.2024 15:00, Geoff Clare wrote:
    Janis Papanagnou wrote:

    I noticed that 'fc' doesn't seem to work on my Limux platform (neither
    with ksh93u+ nor with ksh93u+m). Usually I use that built-in command
    only as 'fc -l' (to list the history entries), and omitting the '-l'
    should execute these commands. Alas, 'fc <from> <to>' doesn't work;
    for example

    $ fc -l 1013 1015
    1013 ls X
    1014 ls Y
    1015 ls Z
    $ fc 1013 1015
    15
    ^C
    ?
    ^Z[1] + Stopped fc 1013 1015
    $ kill %%
    [1] + Terminated fc 1013 1015


    Is that an issue in my environment (or on my platform), or a bug?

    It's an issue with your expectation.

    (Actually my [inappropriate] environment setting; see below.)

    By default, fc starts an editor.
    Presumably you don't have FCEDIT set, as your output shows the default
    editor (ed) was used; it was ed that wrote the "15" and the "?".

    Argh! - Yes, you are right. I was confident that I had a sensible
    definition, but I see that FCEDIT=/bin/ed and it didn't appear
    to me that what I got was an 'ed' prompt. - Thanks!


    If you just want the commands executed, you can specify an editor
    that does nothing:

    fc -e true 1013 1015
    fc -e : 1013 1015

    This is a nice code pattern.


    Or, if you only want to execute one command, you can use -s (without specifying a substitution).

    I had tried this before and got an inconsistent error message (-e
    instead of -s) when [inappropriately] trying for a range

    $ fc -s 1071 1073
    ksh: fc: -e - requires single argument

    so I haven't followed that path further.


    This is all POSIX standard stuff.

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Geoff Clare@21:1/5 to Janis Papanagnou on Tue Jul 2 13:50:29 2024
    Janis Papanagnou wrote:

    On 01.07.2024 15:00, Geoff Clare wrote:

    If you just want the commands executed, you can specify an editor
    that does nothing:

    fc -e true 1013 1015
    fc -e : 1013 1015

    This is a nice code pattern.


    Or, if you only want to execute one command, you can use -s (without
    specifying a substitution).

    I had tried this before and got an inconsistent error message (-e
    instead of -s) when [inappropriately] trying for a range

    $ fc -s 1071 1073
    ksh: fc: -e - requires single argument

    so I haven't followed that path further.

    Yes, you can't give a range with -s (which is why I wrote "if you only
    want to execute one command" above).

    Looks like ksh implements -s by pretending that "-e -" was specified,
    but the output from "--help" implies the relationship is the other way
    round:

    OPTIONS
    -e editor editor specifies the editor to use to edit the history
    command. A value of - for editor is equivalent to
    specifying the -s option.

    It would make more sense for the code to do it that way too, since -s is
    in POSIX but "-e -" isn't.

    --
    Geoff Clare <netnews@gclare.org.uk>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Geoff Clare on Tue Jul 2 18:02:19 2024
    On 02.07.2024 14:50, Geoff Clare wrote:

    Or, if you only want to execute one command, you can use -s (without
    specifying a substitution).

    I had tried this before and got an inconsistent error message (-e
    instead of -s) when [inappropriately] trying for a range

    $ fc -s 1071 1073
    ksh: fc: -e - requires single argument

    so I haven't followed that path further.

    Yes, you can't give a range with -s (which is why I wrote "if you only
    want to execute one command" above).

    Yes, sure. - Above I've just described the experiments I've done
    before your post (and even before I've written my original post
    here). - It was no disrespect, just your post came too late. :-)
    What I tried to say above was that I tried -s and that the error
    message -e contributed to my impression that something is spoiled,
    thus me not following this specific trial.

    Actually, with my original intention to emulate the Emacs-mode ^O
    function in Vi-mode I haven't spent any more time. My impression
    is that it's a function that should be supported as shell builtin.
    It seems to not make sense trying KEYDB traps or grep'ing the
    ${HISTFILE} contents (just to name two thoughts I pondered about).

    Wasn't there some callback facility (maybe also through discipline
    functions) to obtain and manipulate an entered command line before
    it gets evaluated? (I thought to recall something like that. If so
    it might be a way to more easily get the desired function working.
    Must have a look... - but not now.)

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)