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 "-"?
[ 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 .
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".
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
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 ?
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.
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.
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.
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?
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).
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.
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.
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?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 489 |
Nodes: | 16 (2 / 14) |
Uptime: | 33:52:19 |
Calls: | 9,668 |
Calls today: | 3 |
Files: | 13,716 |
Messages: | 6,169,034 |