Sponsored Content
The Lounge What is on Your Mind? Speculative Shell Feature Brainstorming Post 302509025 by tetsujin on Tuesday 29th of March 2011 04:01:19 PM
Old 03-29-2011
Dropping the file handle discussion - I'll read and carefully consider what you had to say on the subject. I do recognize this as an important problem: as I think about these things that I would want to put in a shell, not all of them necessarily fit, and in the end not all of them are worth the trouble.

For now I want to continue the discussion with the assumption that features we talk about would be implemented without too many fundamental changes to how the shell works.

Quote:
Originally Posted by Corona688
You don't need screen to do that, by the way. Any C program can create a PTY.
Well, yeah, any program can create a PTY - but if you want to actually display multiple TTY-using programs simultaneously, you need something like screen or xterm - a virtual terminal. I could write my own virtual terminal like "screen" but for a first pass it'd probably be more productive to bend "screen" to my needs.

Quote:
I'm not exceptionally concerned about running mounds of interactive things in parallel, really. Usually that doesn't make sense.
True... The main use cases I'm thinking about here would be cases where the program expects to display to a TTY. For the jobs to get input from the TTY - well, screen or xterm could handle that but if your loop is full of interactive prompts then maybe you need to redesign the code that's inside that loop, as you say. Smilie But if someone wanted to do that anyway, it could nevertheless be done via the screen mechanism I described...

Quote:
Synchronizing variables would be more of a problem. I'm not 100% sure how it'd work yet, but I can envision the shell processing a set of lines and compiling an order of operations that it shoves into a queue(okay, these four processes all set this variable once, and the thing below this loop reads it once, so let the loop finish before reading this variable...)
Another way to look at this would be to say it's part of an introduction of proper threading to the shell - meaning that multiple loop iterations running concurrently can modify the variable (and the shell would provide enough synchronization to ensure that the environment isn't corrupted, structurally speaking) - and if better synchronization is needed, then the user has to write critical regions into their shell code.

Introducing the concept of threads may complicate other areas of the shell, however: for instance at present if you pipe a bunch of different shell commands together, all but one of those is going to be run in a subshell with no ability to change the environment of the main shell process. Introducing threading would raise the question of whether all those built-in jobs (and even the parenthesis syntax in general) should now be threads. This would be an incompatible change (though behavior of which part of a pipeline is executed in the main shell process varies between shells already) but it might also make sense.

Quote:
wget can print progress to non-terminals, it just prints lines of dots.
My installed version of wget always writes out to /dev/tty (and using some kind of control characters to update the progress bar in-place) when /dev/tty is available.

When there's no TTY (running inside emacs, in this case) the progress bar is redrawn every 50KB or so - on a new line. If two wgets (with no /dev/tty) are run concurrently with shared stdout, the display winds up corrupted as the two processes write to stdout simultaneously: (not necessarily a full line at a time: a dot is written for each kilobyte received)
Code:
   700K .......... ......... 10%  513K 14s
   750K ................. .......... .......... .... .......... .......... .......... .......... 11%  559K 14s
   800K ............. 10%  434K 15s
   750K .......... ............ ........ .......... ......... .......... .......... ............. .......... 11%  488K 15s
   800K .......... ........ 12%  385K 14s
   850K .......... .......... ............. .......... ... ............... ........... .......... 12%  637K 13s
   900K ............ 12%  473K 14s

If you were running those two programs concurrently while you're at the console, watching, that's not a particularly useful way to display them. You don't really need to see all those lines of history, you already know that before you reached 12% you were at 11%, and before that 10%, and so on. (For that matter, that kind of information isn't useful for a log, either... That kind of output is mostly just useful if you want to read it into another program that implements another progress display method.) Really you just want to see the filenames of the files currently being fetched and the progress on each one. wget already has a good mechanism for displaying its own current status: using "screen" or similar makes it easy to take advantage of this.

Quote:
In both cases the output is useful either way when the thing reading them is a script instead of a human, so I don't think it's too important.
Still, regardless of whether the output is readable before you interleave it, it's not going to be readable after you interleave it unless you make the right kind of choice about how the values should be interleaved. (Or, in the case of programs that display to the TTY, some kind of TTY-sharing mechanism.)

A related problem that I didn't address is stderr. Synchronizing on newlines would probably be adequate for most cases, but it'd probably make sense to provide all the same multiplexing/redirection options that stdout gets, in case somebody needed it. (For instance, if you were running gcc in the loop, probably you'd want to synchronize per loop step rather than letting stdout and stderr get interleaved per-line or "whenever"...)
 

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