• Re: Piping to stdin

    From Spiros Bousbouras@21:1/5 to Malcolm McLean on Sun Aug 13 14:27:35 2023
    On Sun, 13 Aug 2023 07:07:55 -0700 (PDT)
    Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
    On Sunday, 13 August 2023 at 14:55:57 UTC+1, Spiros Bousbouras wrote:
    [ Followup-To: comp.unix.programmer ]
    On Sun, 13 Aug 2023 06:42:17 -0700 (PDT)
    Malcolm McLean <malcolm.ar...@gmail.com> wrote:
    On Unix-lke systems, what is the convention for putting a program into a mode where it accepts input from stdin?
    Where the user invokes it directly, he'll normally want input from a file. So
    the normal invocation would be

    myprogram myinput.txt

    But if he just types "myprogram" it should display brief help text. So we can't omit the filename to make the program read from stdin.
    [...]
    So do you pass an option

    myprogram -stdin

    or what is the normal way of solving this?
    - (a single dash) as argument. Even if the programme accepts multiple file name arguments , a single dash among those means "read from stdin".

    So conventionally the file name is "-"?

    Yes.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Joe Pfeiffer@21:1/5 to Spiros Bousbouras on Sun Aug 13 21:26:59 2023
    Spiros Bousbouras <spibou@gmail.com> writes:

    [ Followup-To: comp.unix.programmer ]

    On Sun, 13 Aug 2023 06:42:17 -0700 (PDT)
    Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
    On Unix-lke systems, what is the convention for putting a program into a
    mode where it accepts input from stdin?
    Where the user invokes it directly, he'll normally want input from a file. So
    the normal invocation would be

    myprogram myinput.txt

    But if he just types "myprogram" it should display brief help text. So we >> can't omit the filename to make the program read from stdin.

    I would use a -h option for help text and with no arguments it should read from stdin .

    No, the typical user will expect help text from just typing the command
    name (notwithstanding ancient programs like cat). I typically treat no
    args the same as -h

    So do you pass an option

    myprogram -stdin

    or what is the normal way of solving this?

    - (a single dash) as argument. Even if the programme accepts multiple file name arguments , a single dash among those means "read from stdin".

    Yes, this is what seems common.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Spiros Bousbouras@21:1/5 to Joe Pfeiffer on Mon Aug 14 09:24:06 2023
    On Sun, 13 Aug 2023 21:26:59 -0600
    Joe Pfeiffer <pfeiffer@cs.nmsu.edu> wrote:
    Spiros Bousbouras <spibou@gmail.com> writes:

    [ Followup-To: comp.unix.programmer ]

    On Sun, 13 Aug 2023 06:42:17 -0700 (PDT)
    Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
    On Unix-lke systems, what is the convention for putting a program into a >> mode where it accepts input from stdin?
    Where the user invokes it directly, he'll normally want input from a file. So
    the normal invocation would be

    myprogram myinput.txt

    But if he just types "myprogram" it should display brief help text. So we >> can't omit the filename to make the program read from stdin.

    I would use a -h option for help text and with no arguments it should read
    from stdin .

    No, the typical user will expect help text from just typing the command
    name (notwithstanding ancient programs like cat). I typically treat no
    args the same as -h

    Not to mention grep , awk , sed , sort , bc , od , etc. Being "ancient"
    means that their conventions are more firmly established so why would a
    user expect something else ?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Spiros Bousbouras on Mon Aug 14 11:29:54 2023
    Spiros Bousbouras <spibou@gmail.com> writes:

    On Sun, 13 Aug 2023 21:26:59 -0600
    Joe Pfeiffer <pfeiffer@cs.nmsu.edu> wrote:
    Spiros Bousbouras <spibou@gmail.com> writes:

    [ Followup-To: comp.unix.programmer ]

    On Sun, 13 Aug 2023 06:42:17 -0700 (PDT)
    Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
    On Unix-lke systems, what is the convention for putting a program into a >> >> mode where it accepts input from stdin?
    Where the user invokes it directly, he'll normally want input from a file. So
    the normal invocation would be

    myprogram myinput.txt

    But if he just types "myprogram" it should display brief help text. So we
    can't omit the filename to make the program read from stdin.

    I would use a -h option for help text and with no arguments it should read
    from stdin .

    No, the typical user will expect help text from just typing the command
    name (notwithstanding ancient programs like cat). I typically treat no
    args the same as -h

    Not to mention grep , awk , sed , sort , bc , od , etc. Being "ancient" means that their conventions are more firmly established so why would a
    user expect something else ?

    Agreed. And newer programs will follow the ancient convention. The distinction, it seems to me, is not age but purpose. If you can easily
    see a program being used in a pipeline, it should silently read stdin,
    but if that usage is rare, it should interpret '-' as a convention for
    reading stdin.

    For example, gcc on it's own complains, but

    echo "int f() { return 1; }" | gcc -S -xc - -o -

    works as expected.

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Spiros Bousbouras on Wed Aug 16 20:10:40 2023
    On 2023-08-16, Spiros Bousbouras <spibou@gmail.com> wrote:
    On Wed, 16 Aug 2023 17:37:55 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    Richard Kettlewell <invalid@invalid.invalid> writes:
    David Brown <david.brown@hesbynett.no> writes:
    On 15/08/2023 09:50, Richard Kettlewell wrote:
    The cases I’ve encountered are where someone accidentally creates a
    file with a weird name (starts with - or whatever) and then has
    trouble deleting it. I don’t think they got as far as having
    accidents with wildcards in the cases I remember, but the basic setup
    of a file with a ridiculous name and a non-expert user does happen
    occasionally.

    It's usually sufficient just to put the awkward name inside quotation marks.

    In the case we started with, quoting is not sufficient.

    Doesn't that depend on the type of quote? glob characters (*, ?) are
    treated as regular characters in single quotes, for example.

    The issue is whether a filename may be confused for an option if the
    filename starts with - .Quoting isn't going to help with that.

    It does. There is a quoting mechanism -- which says "the following
    arguments are literal even if they look like options".

    It's a token-level quote. The "--" token escapes a following "-rf"
    token, and others after it.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Spiros Bousbouras@21:1/5 to Scott Lurndal on Wed Aug 16 19:22:38 2023
    On Wed, 16 Aug 2023 17:37:55 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    Richard Kettlewell <invalid@invalid.invalid> writes:
    David Brown <david.brown@hesbynett.no> writes:
    On 15/08/2023 09:50, Richard Kettlewell wrote:
    The cases I’ve encountered are where someone accidentally creates a
    file with a weird name (starts with - or whatever) and then has
    trouble deleting it. I don’t think they got as far as having
    accidents with wildcards in the cases I remember, but the basic setup
    of a file with a ridiculous name and a non-expert user does happen
    occasionally.

    It's usually sufficient just to put the awkward name inside quotation marks.

    In the case we started with, quoting is not sufficient.

    Doesn't that depend on the type of quote? glob characters (*, ?) are treated as regular characters in single quotes, for example.

    The issue is whether a filename may be confused for an option if the
    filename starts with - .Quoting isn't going to help with that.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Kaz Kylheku on Wed Aug 16 20:11:27 2023
    On 2023-08-16, Kaz Kylheku <864-117-4973@kylheku.com> wrote:
    On 2023-08-16, Spiros Bousbouras <spibou@gmail.com> wrote:
    On Wed, 16 Aug 2023 17:37:55 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    Richard Kettlewell <invalid@invalid.invalid> writes:
    David Brown <david.brown@hesbynett.no> writes:
    On 15/08/2023 09:50, Richard Kettlewell wrote:
    The cases I’ve encountered are where someone accidentally creates a >>> >>> file with a weird name (starts with - or whatever) and then has
    trouble deleting it. I don’t think they got as far as having
    accidents with wildcards in the cases I remember, but the basic setup >>> >>> of a file with a ridiculous name and a non-expert user does happen
    occasionally.

    It's usually sufficient just to put the awkward name inside quotation marks.

    In the case we started with, quoting is not sufficient.

    Doesn't that depend on the type of quote? glob characters (*, ?) are
    treated as regular characters in single quotes, for example.

    The issue is whether a filename may be confused for an option if the
    filename starts with - .Quoting isn't going to help with that.

    It does. There is a quoting mechanism -- which says "the following
    arguments are literal even if they look like options".

    It's a token-level quote. The "--" token escapes a following "-rf"
    token, and others after it.

    Ah, but of course, that is of no help with -, which is a non-option
    argument.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Geoff Clare@21:1/5 to Phil Carmody on Thu Aug 17 13:49:49 2023
    Phil Carmody wrote:

    Muttley@dastardlyhq.com writes:

    Apple arguably are even worse right now - case aware but case insensitive
    unless you use wildcards on the command line when suddenly case matters again.
    Hopeless.

    eg:
    fenris$ touch HELLO
    fenris$ ls hello
    hello
    fenris$ ls H*
    HELLO
    fenris$ ls h*
    ls: h*: No such file or directory

    That I didn't know. Wow - if that's an actual interactive session being quoted, that's frightening. Thanks for reminding me why my installation
    of linux on my Apple G5 box wasn't moment too soon. How can people live
    with such wrongthink?

    They don't have to: they can configure the filesystem that contains
    their home directory to be properly case sensitive.

    I have access to an ancient MacBook which is configured that way:

    $ uname -sr
    Darwin 15.4.0
    $ touch HELLO
    $ ls hello
    ls: hello: No such file or directory
    $ ls H*
    HELLO
    $ ls h*
    ls: h*: No such file or directory

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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Geoff Clare@21:1/5 to Keith Thompson on Thu Aug 17 13:34:32 2023
    Keith Thompson wrote:

    If you have a file named -r, you can delete it with `rm ./-r`, or
    `rm -- -r` if your rm implementation supports that (POSIX doesn't
    specify it).

    POSIX does specify that "rm -- -r" removes a file called -r.

    Almost all the utilities have a statement under OPTIONS that they
    conform to XBD 12.2 Utility Syntax Guidelines (in some cases with
    exceptions for specific individual guidelines). The requirement to
    support "--" is guideline 10.

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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Muttley@dastardlyhq.com@21:1/5 to Geoff Clare on Thu Aug 17 15:15:24 2023
    On Thu, 17 Aug 2023 13:49:49 +0100
    Geoff Clare <geoff@clare.See-My-Signature.invalid> wrote:
    Phil Carmody wrote:

    Muttley@dastardlyhq.com writes:

    Apple arguably are even worse right now - case aware but case insensitive >>> unless you use wildcards on the command line when suddenly case matters >again.
    Hopeless.

    eg:
    fenris$ touch HELLO
    fenris$ ls hello
    hello
    fenris$ ls H*
    HELLO
    fenris$ ls h*
    ls: h*: No such file or directory

    That I didn't know. Wow - if that's an actual interactive session being
    quoted, that's frightening. Thanks for reminding me why my installation
    of linux on my Apple G5 box wasn't moment too soon. How can people live
    with such wrongthink?

    They don't have to: they can configure the filesystem that contains
    their home directory to be properly case sensitive.

    You can, but it can break a lot of programs that expect case insensitivity.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Keith Thompson@21:1/5 to Geoff Clare on Thu Aug 17 14:27:51 2023
    Geoff Clare <geoff@clare.See-My-Signature.invalid> writes:
    Keith Thompson wrote:

    If you have a file named -r, you can delete it with `rm ./-r`, or
    `rm -- -r` if your rm implementation supports that (POSIX doesn't
    specify it).

    POSIX does specify that "rm -- -r" removes a file called -r.

    Almost all the utilities have a statement under OPTIONS that they
    conform to XBD 12.2 Utility Syntax Guidelines (in some cases with
    exceptions for specific individual guidelines). The requirement to
    support "--" is guideline 10.

    Quite right, I sit corrected.

    https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02

    --
    Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
    Will write code for food.
    void Void(void) { Void(); } /* The recursive call of the void */

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kalevi Kolttonen@21:1/5 to Ben Bacarisse on Sun Aug 20 02:02:19 2023
    In comp.unix.programmer Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
    Phil Carmody <pc+usenet@asdf.org> writes:

    Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
    Some file systems (depending on mount options) can have complex rules
    such as rejecting any name with an invalid UTF-8 sequence.

    Oooh, now I'm tempted to name files in Latin-1, to deliberately break
    filesystems that make such assumptions!

    Why?

    I suppose that was some kind of a joke.

    Anyway, one cannot "break" those filesystems as the
    invalid names are simply rejected. I am not 100%
    sure but ZFS might be an instance of such a filesystem.

    br,
    KK

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