Imagine I have a script, which contains the goto command.The goto command will search in the std input for a line like this : jumpHere.But the std input is by default the terminal. It only makes sense if the file/script is the std input for the goto command. So where/who/what is changing the std input?ps. I'm talking about old Thompson-Shell, Unix v6.
How does executing a file change the std input?
shell;shell script;terminal
Note that goto was a separate utility, so not part of the Thompson shell per-se.When you invoke the Thomson shell as:sh the-scriptsh opens the-script on stdin (fd 0) as if you had writtensh < the-scriptinstead.The goto command will seek stdin back to the beginning (which obviously if stdin were a terminal and not a regular file wouldn't work) then look for the label in there and would leave the cursor in the file just after that. Then the shell would carry on from there.If you wanted a command in your script to read from what stdin was originally, you'd use the <- special redirection operator:cmd <- Note that with that same goto command, your script would also work with bash if you invoke your Thomson shell script as:bash < the-scriptksh93 can emulate that goto with special seeking redirection operators. For instance this Thomson shell script:echo Start: startls -ld /proc/self/fd/0sleep 1goto startecho End never reachedCould be written in ksh93 like:echo Start: startls -ld /proc/self/fd/0sleep 1exec <#((0)) <#: startecho End never reachedBoth would run (provided you have the V6 goto command) with ksh93 when invoked as:ksh93 < the-script