Sponsored Content
The Lounge What is on Your Mind? Speculative Shell Feature Brainstorming Post 302507820 by Corona688 on Thursday 24th of March 2011 11:47:39 PM
Old 03-25-2011
Quote:
Originally Posted by tetsujin
You do make a good point here, I think... It may be a good argument against the idea that things I've described can coexist with the more standard shell approach.
There's still a contradiction in that.
Quote:
If everything's stored as a string, or if you pretend it is, then you can't specialize for different data types. For polymorphism to work you need a clear idea of the "class" that defines the object's behavior.
If you want these features, don't use a shell language. You can't stick a polymorphic object into a commandline argument.
Quote:
If one sticks to the idea that everything should have an automatic translation back to string, then any time you do an operation on that thing there's the question "did you mean this to be a string operation?"
There's no ambiguity. The answer is always, always "yes". Remember that this is a shell. You have to put these things into commandline programs. Strings are the only things that make sense.
Quote:
For instance, a fairly common expectation is that string concatenation (which, of course, is not addition) should use the addition operator.
I haven't seriously used a language that did that since I stopped writing in BASIC.
Quote:
You see this a lot in bash as well. "Is that numeric comparison or lexicographical string comparison?" I kind of hate that, honestly. Smilie
Well, nobody forced you to use a shell language.
Quote:
I think there will be other types of "special" variable. I can't give each one its own special character...
And again you've missed the point. Every time you decide something deserves to be a special case and give it its own, special types and syntax you create more and more walls between your builtins' syntax and what you allow the programmer to do. Don't specialize, generalize.
Quote:
I don't think I've described anything that affects stdin/stdout...
Yeah, just everything else. More and more special magic things.
Quote:
Didn't they get rid of the argument limit? (In Linux, anyway...?)
No.
Quote:
And did it even apply to builtin echo?
Who says you're running "echo"? Feeding them all into echo like that would have side-effects on the contents of the string.

Besides, imagine what you'd be able to do by fiddling IFS. You could make it produce all the strings seperated by commas, or by NULLs, without needing an external program.
Quote:
I have, in a few places, considered the possibility that these objects could coexist with the current mechanism for opening files (as in "exec 3<filename" or "exec {f}<filename" for the current mechanism, something else for this "special" crap) but if I'm not going for Bourne compatibility I think there's no point.
The point is to not deny yourself features. Just because you don't need it this instant doesn't mean you're not going to need it the instant you make it opaque. They've tried many times. stdio tried to wall it all off behind an opaque pointer because you don't "need" anything else, and ended up needing fdopen() and fileno() because sometimes, you actually, genuinely need it. They tried hiding it all behind C++ iostreams and people wouldn't have it, resulting in a stew of nonstandard iostream extensions allowing you to get or at least set the file number for one of them. Stop deciding what programmers "really need" and just hand out the stupid fileno. All you have to do is shove it in a string variable and it's as tidy as you could want.
Quote:
It's the difference between having "open this file on this specific descriptor table index, leave it open and pass it on to all child processes until I tell you otherwise" and "open this thing, I don't care where, close it when I'm not using it any more and pass it on only when I say so". I think the latter makes a lot more sense.
False dilemma. You don't have to have it 100% your way to get everything you want. Just an exec-like command that puts a file descriptor number in a string does what you want. And a shell builtin to set the kernel's close-on-exec ioctl gives you the rest. You could even have that as a flag for opening it. But as the default? Remember that people other than you might have to program in this language, and might expect "open the file" to just open the file without cleaning their laundry too.
Quote:
Yeeg, there's an awkward distinction...
It makes perfect sense when you think about it -- IFS is the character a shell splits strings on! How do you stop a string from being split? Quote it, of course.
Quote:
I mean, I get the distinction in the first two commands, even appreciate it: without quotes, ${A[*]} expands each array element to a positional argument, preserving the distinction between neighboring elements - while if you quote it, it's applying $IFS.
There's nothing inconsistent about it, it's always substituting in the commas -- but if you don't quote it, it splits on the commas just like it'd usually split on spaces! This is what IFS does -- it's the characters the shell splits on, not just in arrays, but most substitution.
Quote:
(Obviously when I find things that I think are wrong with bash, that doesn't undermine the merits of bash's basic approach - I don't mean it that way... Just... this seems very inconsistent!)
Don't jump to conclusions, take a closer look.
Quote:
...You have lost information in the translation.
Only because you intentionally threw it away.
Quote:
Hence, I think it's inappropriate to treat arrays as string-equivalent.
That's quite all right, but if you don't want to program in a shell language, you don't have to program in a shell language. It's all about strings and splitting strings and can't really be anything else because that's the only thing you can put in a commandline.
Quote:
However, it's not the common case that someone will need to open a file on a specific FD and have all child processes inherit that file on that specific numeric FD.
That's good, because they don't:
Code:
command < file | command2 | command3

Only the first command of that line gets it. You have exceedingly fine control over it already.
Quote:
As such, I think it's reasonable to fit the syntax to what I believe is the more common case of opening a file: within the shell, you don't care what numeric FD it winds up on.
You always care what FD it winds up on: Generally zero.
Quote:
It's only when you launch a child process that uses that numeric FD - and most child processes won't.
You know what they say about assumptions: They make an ass of you and me.

How users want to use files is a question of programming style. Don't give them less options, give them more!


Quote:
It doesn't get me scoped file handles
Yes it can.

Code:
(
        open FOUT>filename
        open FIN<filename
        # How about this syntax, or something like it, for an implied close-on-exec?
        open -FD<filename
        
        do_stuff_with <$FIN >$FOUT
)
# How about a new kind of bracket that scopes files but not variables?

${
        open -FD<filename
        stuff <$FD
$}

Quote:
Getting rid of the traditional mechanism for opening files in the shell, in which the user explicitly selects a numeric FD?
Code:
exec 4<file
cmd --do-something-with-fd=4

Maybe. I know of two programs that operate like this.
The point is, you don't need to throw away this feature. You can get what you want without throwing it away and adding 9 new variable types plus operator overloading instead. That you don't find it personally useful doesn't mean it's useless.
Quote:
As such I think this kind of blanket redirection doesn't make a lot of sense.
This kind of "blanket redirection" is the foundation of how files, pipes, redirection, and terminals all behave. If you want to close that all off, make these "special cases" all part of your language instead of part of the environment, fine, but that's not a shell.
Quote:
Give me a little credit here. I know how open(), dup(), etc. work.
...but I'm not sure you understand why.
Quote:
But the relevant point is that when the user runs cmd < filename they don't care what that call to open() returned.
So what?
Quote:
They don't need to. They never need to provide or obtain the answer to that question.
We've been asked on these forums before, how to do exactly that.
Quote:
Poor choice of words, perhaps. I was inviting you to think about how frequent that usage is (as in "measure frequency of this occurrence" rather than "boy, is that occurrence frequent!"), with the suggestion that it isn't common. Seriously, do you do that a lot?
Occasionally. If you removed that feature from the shell I'd have to hack it back in since there's things that can't be done without it.
Quote:
What are you getting at here? I don't get it. I read it and it just looks like you're being rude, giving me a hard time for using the word "special" or something. I don't know if that's your intent.
Think back to how I started my post, explaining about a language crammed with special cases that had to be worked around in very awkward ways. The more special cases you add, the more awkward corners you add.
Quote:
It doesn't get me scoped file handles, or control over which child processes inherit that open file descriptor, which is kind of where this whole thing started. Smilie
You can get that kind of control without completely obliterating the model we have.
Quote:
As for fileno():
Within the shell it wouldn't normally be important where an open file resides.
It's not "usually" relevant in a C program either, but it's quite important enough.
Quote:
The use case would be to dup the file descriptor to some other number via redirection syntax:
Code:
# $fh is some "file handle" - a managed open file descriptor.
# User doesn't generally care what its number is, and its behavior in substitutions is not entirely straightforward.
$ read <& $fh

I'd like to point out, yet again, that this is already valid shell syntax. You don't need to add new variable types to make this works. Set the string fh to a valid file descriptor number, use a builtin to set close-on-exec, and you've got it.
Quote:
Mostly there's no point in knowing where it is as long as you can control where it's going to be.

But there's no reason a feature couldn't be included to determine where the file is.
My question is: Why make it a new special type of variable in the first place? File descriptors are actually, really, genuinely integers. You're actually making it harder on yourself intentionally hiding the integer from view instead of just storing it in a variable where anything, shell included, can use it.

Last edited by Corona688; 03-25-2011 at 12:54 AM..
 

4 More Discussions You Might Find Interesting

1. SCO

BASH-like feature. is possible ?

Greetings... i was wondering if there is any shell configuration or third party application that enables the command history by pressing keyboard up arrow, like GNU/BASH does or are there an SCO compatible bash versio to download? where ? just wondering (sory my stinky english) (2 Replies)
Discussion started by: nEuRoMaNcEr
2 Replies

2. Shell Programming and Scripting

Creating a command history feature in a simple UNIX shell using C

I'm trying to write a history feature to a very simple UNIX shell that will list the last 10 commands used when control-c is pressed. A user can then run a previous command by typing r x, where x is the first letter of the command. I'm having quite a bit of trouble figuring out what I need to do, I... (2 Replies)
Discussion started by: -=Cn=-
2 Replies

3. UNIX for Dummies Questions & Answers

brainstorming automated response

I am managing a database of files for which there is a drop-box and multiple users. what i would like to do is set a criteria for files coming into the drop-box based on file structure. (they must be like this W*/image/W*-1234/0-999.tif) If the files do not match the criteria i want them to be... (1 Reply)
Discussion started by: Movomito
1 Replies

4. UNIX for Beginners Questions & Answers

Can we create any check-point feature in shell ?

I have a script as below and say its failed @ function fs_ck {} then it should exit and next time i execute it it should start from fs_ck {} only Please advise #!/bin/bash logging {} fs_ck {} bkp {} dply {} ## main function### echo Sstarting script echo '####' logging fs_ck... (3 Replies)
Discussion started by: abhaydas
3 Replies
All times are GMT -4. The time now is 10:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy