News for hackers. Stuff that matters.
Re:Effective Shell by kazinator on Tuesday June 21, 2022 @09:42PM (#31831142)
This is going to confuse the frankfurter out of a newbie. First it presents the idea that Windows has a shell, and even multiple shell programs. Screenshots 'n' everything.

But then, nope:

> Windows is not anything like Linux under the hood. So to get a shell working, we have three options:

> Use a tool which provides common Linux tools which have been written to work with Windows

> Use a "virtual machine" running Linux

> Use the Windows Subsystem for Linux

What "common Linux tools which have been written to work with Windows" is referring to is installing Cygwin.

This a fairly hamfisted presentation of a subject matter that could be handled in a way that is simultaneously easier to grasp and factually correct.

First of all, your goal is to teach about a specific command interpreter language, you really want to clarify how there are multiple ones which have different syntax, and brush that whole topic aside as fast as possible.

> You can see what the version is of your shell by running:

> bash --version

Yikes. If we know we are running Bash, the way to know what version it is is:

  echo $BASH_VERSION
and not to run another instance of Bash.

Can this book teach something simple, like comments?

> The shell ignores any text which follows a # hash symbol.

Wrong:

  $ echo 'all of # this is seen'
  all of # this is seen
"this is seen" looks like an example of "any text" to me.

A hash comment marker is ignored if it is not quoted and escaped so as to be part of a word. The hash is also part of certain bits of syntax:

  $#               (dollar hash) number of positional parameters

  ${variable#pat}  expand the content of variable, chopping off
                   a leading portion which matches the pat pattern.
                   Example:

                     $ echo $TERM
                     xterm-256color

                     $ echo ${TERM#xte}
                     rm-256color
Re:Effective Shell by chasil on Wednesday June 22, 2022 @12:35AM (#31832057)
The classic Windows shell has many flaws in its design, appears to have come from OS/2, and it's amazing that it works at all for how it has been used:

https://blog.nullspace.io/batch.html

Powershell is a new arrival, limited outside of Windows. I admit that I don't know it.

The POSIX shell also has severe problems with ambiguity, and it is not an LR-parsed language:

https://archive.fosdem.org/2018/schedule/event/code_parsing_...

Use the right tool for the job, imperfect as they may be.

It is unfortunate that awk didn't grow and supplant the shell, as for many years the BWK "One True Awk" did use straightforward lex and yacc grammars.

Re:Effective Shell by layer8 on Wednesday June 22, 2022 @08:14AM (#31835025)
> The classic Windows shell […] appears to have come from OS/2

It’s actually based on the DOS command shell [1], which in turn was modeled after CP/M [2].

[1] https://en.m.wikipedia.org/wiki/COMMAND.COM

[2] https://en.m.wikipedia.org/wiki/CP/M

Re:Effective Shell by chasil on Wednesday June 22, 2022 @09:55AM (#31836017)
Alas, incorrect. Notice the "Comparison with COMMAND.COM" section.

https://en.wikipedia.org/wiki/Cmd.exe

Re:Effective Shell by layer8 on Wednesday June 22, 2022 @12:19PM (#31838019)
Could you elaborate on what exactly you think is incorrect?
Re:Effective Shell by chasil on Wednesday June 22, 2022 @05:39PM (#31842194)
From the wiki, command.com did not run pipelines in parallel, and in consequence could not redirect standard error:

"For example, on OS/2 and Windows, it can use real pipes in command pipelines, allowing both sides of the pipeline to run concurrently. As a result, it is possible to redirect the standard error stream. (COMMAND.COM uses temporary files, and runs the two sides serially, one after the other.)"

Obviously, this process and I/O management would require a massive rewrite, sufficient to make cmd.exe a new (but somewhat compatible) implementation. This was not possible in DOS or CP/M.

Delayed variable expansion, pushd/popd, file name completion, expression evaluation and improved control structures are all fundamental changes that are strongly influenced by the Berkeley C Shell written by Bill Joy. The wiki specifically mentions the C Shell.

The 8086(/8) binary for command.com is not found in modern windows (I think the "wow16" layer was removed from 64-bit windows); cmd.exe is a 32-bit binary running under wow32, which it must be to invoke these new features in system calls that could not exist in DOS.

The wiki says this about the relation between command.com and cmd.exe:

"cmd.exe is the counterpart of COMMAND.COM in DOS and Windows 9x systems, and analogous to the Unix shells used on Unix-like systems."

I think that very little source code from command.com ended up in cmd.exe.

Re:Effective Shell by layer8 on Wednesday June 22, 2022 @06:31PM (#31842695)
Yeah, I didn’t mean it in terms of of source code and implementation, and certainly a lot of features were added since DOS, but since both OS/2 and Windows (NT) were intended to be successors of DOS, their shell took over the syntax and conventions of the DOS shell.
Re:Effective Shell by chasil on Wednesday June 22, 2022 @06:53PM (#31842928)
...but also some of Bill Joy's influence as well.

It is compatible with, but distinct from what preceded it.

Re:Effective Shell by dwmkerr on Wednesday June 22, 2022 @09:03AM (#31835512)
Hello, this is dwmkerr the author - your comments are all spot on - the earlier in the book you go the more work it needs, I've learnt a lot along the way TBH probably the entire first part needs a rewrite, that's actually going on at the moment as I'm working with a publisher.

I've linked to this post/comments on the repo (issue #210), they should all get addressed but it might be a while before the online version gets sorted, I'm closing out the final chapters online, once I've done this I'll likely go back to the beginning and rewrite/edit/put in a more consistent style (more code snippets, fewer screenshots etc).

Re:Effective Shell by tpoacher on Wednesday June 22, 2022 @04:10AM (#31833260)
I agree with all your comments from a technical point of view.

I disagree with all of them from an educational point of view.

Having said that, it helps to clarify whether the audience is technical or education oriented. The title implies a technical book, so I'm with you on the comments.

Re:Effective Shell by kazinator on Wednesday June 22, 2022 @04:42AM (#31833441)
For the education oriented audience you need to explain everything, in some good order of revelation. Ideally not all at once. What is it that we are calling "shell"? Why is it called that? Where does it come from? Why are there different kinds of these things? Why do we go out of our way to install some other one intended for some other system? What's Linux?

This author doesn't have a chance in a room full of newbies. You have to have your technical dope straight, and it's not enough.

Re:Effective Shell by basdp on Wednesday June 22, 2022 @07:30AM (#31834604)
It is often best to present a problem or a definition in a simplified way. After grasping the basics, we can extend or go into more depth. Otherwise, students can’t see the forest for the trees. Of course it is still important to state that the definition is presented in a simplified form.
Re:Effective Shell by jwilk on Wednesday June 22, 2022 @11:45AM (#31837564)
Another case where # does not start a comment:

  $ echo foo#bar
  foo#bar
Re:Effective Shell by Rerarom on Wednesday June 22, 2022 @10:37AM (#31836563)
Windows has a shell, it's called explorer.exe :)
Re:Effective Shell by kazinator on Wednesday June 22, 2022 @11:57AM (#31837732)
This is indeed the thing that Windows has called "shell" before adopting that word for command interpreters (PowerShell).

explorer.exe uses the "ShellApi" to do some of its things, which applications can also use, like launching a file via its associated application (ShellExecute/ShellExecuteEx).

Re:Effective Shell by aynawn on Wednesday June 22, 2022 @12:23AM (#31831993)
These are great comments. The code is open source. I'm sure the owner would love a pull request that would address these concerns.
Re:Effective Shell by kazinator on Wednesday June 22, 2022 @02:04AM (#31832565)
I don't want to discourage you, but if you know the subject matter and are inclined to work on a book, you should just write your own from scratch as the sole author: the normal way most books are written.

(I personally wouldn't write a book about the shell. I would be too paralyzed by the thought that at any moment, Stéphane Chazelas might crack it open.)

Re:Effective Shell by basdp on Wednesday June 22, 2022 @07:31AM (#31834613)
The amount of people writing books on subjects as a way of learning something new, is too high. I’ve seen so much trash these days. Especially game design or programming books.