Goto - UNIX v6 Manual Questions

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Goto - UNIX v6 Manual Questions
# 1  
Old 12-24-2014
Questions regarding command manual

Hey Smilie I am trying to understand the command goto.
I have some questions regarding the goto manual.

Goto is allowed only when the Shell is taking commands from a file.
What does the underlined part mean?
I'm not allowed to type goto in the shell? But if goto is written into a file everything is okay?

The file is searched from the beginning for a line beginning with `:' followed by one or more spaces followed by the label.
So if a part of my file looks like this
goto end

Then he would look for a part like this
: end

But I have seen some scripts and I think they were from Unix v6, it looked everytime like this

So what is now the right order?

If such a line is found, the goto command returns. Since the read pointer in the command file points to the line after the label, the effect is to cause the Shell to transfer to the labelled line.
Is it legal to write any other command in the line with the ":"?
For example
:end echo "Hello"

end: echo "Hello"

I'm not expecting that one person answers all 3 questions, you can pick the one you like.

Thank you for your help
and Merry Christmas Smilie

Ps. I mean this manual:

Last edited by orbit; 01-05-2015 at 03:18 PM..
# 2  
Old 12-24-2014
This seems to me is referring to the historical Thompson shell (Its successor Bourne Shell in UNIX v7 did not have a goto...)

I think it means that you cannot use gotos if you use the shell interactively.
V6 Thompson Shell Port - Manuals - GOTO(1)

Presumably because there is a separate, external goto command that needs to go look for the goto label, once invoked

I would think that if the manual is explicit like that, only : end would be allowed (: being the first character on the line) with any number of spaces. The other label is maybe from another script, perhaps sed ?
See also :
V6 Thompson Shell Port - Manuals - GOTO(1)

If such a line is found, goto repositions the command-file offset to the line after the label and exits
V6 Thompson Shell Port - Manuals - GOTO(1)

So it does seem that no commands will be processed on the line with the label.

Last edited by Scrutinizer; 12-24-2014 at 12:09 PM..
These 2 Users Gave Thanks to Scrutinizer For This Post:
# 3  
Old 12-24-2014
The Thompson goto command was bizarre because it was not a shell built-in. It was actually an external command. Decisions like this were made to get the thing to run in a 16 bit machine.

First of all the label concept was piggy-backed onto the colon command. It is a command that does nothing. It still exists today in bash and ksh. I hope you have heard of it. You can give the colon command arguments which the shell "processes" but the command itself ignores. This was used to make the colon command a form of comment. The leading number-sign comment had not yet appeared. A comment like this:
: we should not do stuff like > /etc/passwd

was harmful because the shell would try to send the colon command's output to /etc/passwd. You had to be sure that your comments had no side effects. You could put the : command anywhere you want. The shell would know it should do nothing.

But a colon command used as label had additional restrictions becuase it had to be processed by /bin/goto. There were various versions of /bin/goto. Your label had to match whatever rules your version of /bin/goto had. The goto command used some magic to reposition the shell's input file. This means the input file has to be seekable. A file on paper tape is an example of a non-seekable file. A file on a deck of cards is another example.

The alternate syntax you have a seen "label:" is what csh uses.

Warning: I don't use goto's so maybe some of this is wrong.
This User Gave Thanks to Perderabo For This Post:
# 4  
Old 12-25-2014
Thank you both for your great answers Smilie

I have still some questions.

I think it means that you cannot use gotos if you use the shell interactively.
What does "interactively" mean? How do you use the shell interactively?

What is a label? Is it a string with or without spaces? Is "the end" also a label?
And I could use:
: the end

Is there a man page for colon command ( : )? I tried man colon, but nothing..

Why would it make a difference if goto was a shell built-in?
# 5  
Old 12-25-2014
You can find a man page for : in the Man Pages section on this forum here: colon(1P)
This User Gave Thanks to Don Cragun For This Post:
# 6  
Old 12-26-2014
@1: By typing commands on the command line and executing them by using "enter".
@2: The man pages does not seem to specify whether or not spaces can be used, but I would just control the urge to use them.
@3: Note that it is piggy-backed on the colon command. If the shell arrives on that line, other than through a goto, the colon command gets executed and nothing happens. When you get to that line through the goto command, the colon acts as a label, and the actual colon command does not get executed..
This User Gave Thanks to Scrutinizer For This Post:
# 7  
Old 12-26-2014
@4: If goto was a built-in in the shell, the shell might be able to find the labels in the script it was executing (and would be able to handle goto in an interactive shell) instead of needing to find and read the file containing the script.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

A dash to GOTO or a dash from GOTO, that is the question...

Well, guys I saw a question about GOTO for Python. So this gave me the inspiration to attempt a GOTO function for 'dash', (bash and ksh too). Machine: MBP OSX 10.14.3, default bash terminal, calling '#!/usr/local/bin/dash'... This is purely a fun project to see if it is possible in PURE... (3 Replies)
Discussion started by: wisecracker
3 Replies

2. Shell Programming and Scripting

"goto" like command in UNIX

Hi, echo "yes or no?" read ans case $ans in *) echo "yes" ;; *) echo "no" ;; *) echo "yes or no only" #here, if the answer is not "Y" or "N", I want to go back to asking "yes or no?" (9 Replies)
Discussion started by: erin00
9 Replies

3. Shell Programming and Scripting

How to use GOTO stmt in Unix scripting?

my code does somthing like this: #!bin/ksh sqlplus / | While read id do temp=`echo $id` i = i+1 done j=0 while do --connecting to sql and executing a Stored proc for 1st id --checking for the status status = $? if error --need to... (1 Reply)
Discussion started by: RP09
1 Replies

4. UNIX for Dummies Questions & Answers

Manual run a script on UNIX

Hi,I'm currently working on an dev environment that has no jobs to run the scripts.How can I manual run the scripts. on Unix? ---------- Post updated at 05:45 AM ---------- Previous update was at 05:43 AM ---------- Is it something like this.... ../int/inbound>./ inputfilename ... (5 Replies)
Discussion started by: sonja
5 Replies

5. Shell Programming and Scripting

unix manual needed :)

hi guys... am new 2 dis unix world... am in need of a unix manual... cud sum1 pls post sum links 2 download it?>?>? :confused: Danks in advance... ;) ;) ;) (1 Reply)
Discussion started by: sundar_shankar
1 Replies

6. UNIX for Dummies Questions & Answers

New To Unix - Some Questions!

1) Can a script be made to ignore all signals. 2) Does the parent process always picks up the exit status of its children. 3) Can one program give rise to multiple processes. 4) Is a file is synonymous with a process. 5) Is the kill command only used to kill a running process. (1 Reply)
Discussion started by: yahoo14
1 Replies

7. Shell Programming and Scripting

Unix version of gosub or goto??

Is there a Unix (Solaris v8 ksh) version of the old basic command gosub or goto? I've researched the return command, but can't identify the command to return from. I am not trying to return from a function. Can someone give me a basic understanding of this please? Thanks so much in advance for... (3 Replies)
Discussion started by: gozer13
3 Replies

8. OS X (Apple)

UNIX Commands / Manual

Hi Does anyone know were to go (web link please?) to learn the BACIS of UNIX in OS X, I would like to know a little more about unix (for the apple) but seem to get lost in all the wen sites, and idealy find a site where i could download a manual for the unix shell in OS X. Any ideas? (4 Replies)
Discussion started by: adrianmoore
4 Replies

9. News, Links, Events and Announcements

Unix Manual (man-page) pages in HTML

LINK: Unix Manual (man page) pages in HTML : More then 100 Commands found on a Unix system mannual pages can be obtained/refered here. Good Link.. (1 Reply)
Discussion started by: killerserv
1 Replies
Login or Register to Ask a Question

Featured Tech Videos