Sponsored Content
The Lounge What is on Your Mind? Speculative Shell Feature Brainstorming Post 302508027 by tetsujin on Friday 25th of March 2011 12:26:44 PM
Old 03-25-2011
Quote:
Originally Posted by Corona688
If you want these features, don't use a shell language.
Well, nobody forced you to use a shell language.
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.
One can take this argument to the extreme: say anything that's not part of one of the "standard" commonly-used shells is not a feature of a "shell language". If it wasn't invented at least 15 years ago and implemented as part of something with "sh" in the name, it's no good.

One could also take the broader view: if features are identified that could be of value, find a way to incorporate them while still keeping the shell as conceptually sound as possible.

Quote:
You can't stick a polymorphic object into a commandline argument.
True, just like you can't stick an array into a command line argument. You can stick a representation of an array into a command line argument, you can stick array elements into separate command line arguments - but not the array itself, as a single element.

Quote:
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".
Unless you're doing a mathematical operation, for instance.


Quote:
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.
Shell doesn't use the addition operator for string concatenation, so there you go.

Quote:
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.
The latter would be great - but as far as I can tell you can't store a null byte in a shell variable - and therefore you can't specify the null byte as $IFS.

Though, again, that could be fixed without revolutionary change: just make it possible to create a variable in the shell whose contents include a zero byte. You wouldn't be able to export it, of course ('cause the zero byte would be taken as a terminator) but it'd still be useful internally as $IFS.

Quote:
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.
Removing features is sometimes necessary to incorporate new ideas and result in a coherent whole. If every design decision is hobbled by a strict "break nothing that already exists", the process goes nowhere.

Quote:
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.
Other people might expect lots of things. If they're unwilling to learn a new set of rules, nobody is forcing them to use my shell language, you know? Obviously not everyone is going to think the "improvements" I choose to make are improvements. Different people have different ideas. But progress is not made unless ideas are tested.

Quote:
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!
That is not what it's doing.

If you don't quote it, it expands the variable's elements to separate arguments on the command where it appears. (If an array element contains $IFS, the shell does not split that argument when the array reference is expanded.)

The bit that's really screwy is if you do this:
Code:
$ b="${A[*]}"
$ echo $b

$b is not an array, and I've explicitly set it to the quoted (that is, delimited) form of A's contents. But in this case 'echo $b' produces the same result as 'echo ${A[*]}' - $b is expanded to positional arguments as if it were an array (even though it's not an array, and was initialized with a quoted string!)

I don't see how that can be anything but a bug...

But as I said - I don't want to leave the impression that I'm taking bugs as evidence that there's something wrong with the fundamental approach. That wouldn't be sensible or fair.

Quote:
Don't jump to conclusions, take a closer look.
I am taking a closer look. And I already have. I know enough about bash that I can answer the kinds of questions about it that most people don't ask. And sometimes, in answering them, I learn a bit more about Bash's strengths.

Quote:
Quote:
...You have lost information in the translation. (From array to flat string)
Only because you intentionally threw it away.
On the contrary: you have to bend over backward to translate arrays to strings in a way that preserves their structure. To do it right requires translating the array contents to syntax.

I did, after all, translate the array to a string in exactly the same way as you did. Hence, my argument that arrays don't translate to strings. They are an exception to the common rule in the shell that everything should translate neatly to string form.

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.
[/quote]

That isn't the case I'm talking about.

Code:
# open the file in the shell environment
$ exec 7<file
$ cmd1 | cmd2 | cmd3
# Which processes have FD 7 open?  Which ones needed it?

Quote:
You always care what FD it winds up on: Generally zero.
Ugh. This is the problem with no nested quotes.

You had pointed out that when you open a file and immediately redirect it to FD 0 (or whatever) the open() call initially puts it on a different FD, and a dup() call moves it to FD 0 for the context to which the redirection applies.

I pointed out that this has no bearing on anything. Nobody cares what that "intermediate" FD number was, they only care about the final one that applies to their process.

Quote:
You know what they say about assumptions: They make an ass of you and me.
Strict adherence to this rule is the path to madness via Solipism.

So, yeah, I'll make assumptions here and there. That's how language design works, you start with an idea of how things could or should work. It doesn't mean it's always true, and the real proof of whether the idea was any good is in the implementation and how it plays out in actual use.

Quote:
How users want to use files is a question of programming style. Don't give them less options, give them more!
Sometimes "more options" really does just make the language a mess. Remember how we were talking about Perl a little while ago?

Quote:
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
)

You're scoping the file descriptors and their variables by using subshell syntax. That means you are unavoidably limiting the scope of everything else, too. If you wanted to use this block to read a file and populate a variable, you're out of luck, 'cause that variable binding won't make it outside of the "subshell" block.

Quote:
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
You're taking this all-or-nothing kind of position and you haven't justified it. I can remove "exec 7<file" from shell syntax and replace it with improved support for redirecting code blocks (i.e. provide code blocks that aren't loops or subshells) - I don't see how anything of value is lost.

Quote:
I'd like to point out, yet again, that this is already valid shell syntax.
I know it's already valid shell syntax. That's why I'm using it as an example of how things could work. As pre-existing syntax, it's something that you can read and know what it's supposed to be doing. I don't have to explain what it does, 'cause you already know.

Quote:
My question is: Why make it a new special type of variable in the first place?
Because if file descriptors are "just integers" then the shell can't manage their lifetime. Scoping is a worthwhile feature IMO.
 

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 02:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy