"goto" like command in UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting "goto" like command in UNIX
# 8  
Old 03-05-2014
Quote:
Originally Posted by fpmurphy
Sure it does. The break and continue statements are limited gotos.
Any kind of branching statement can be considered as, and implemented as, a limited goto. Which doesn't mean they're all the same thing.
# 9  
Old 03-05-2014
Quote:
Originally Posted by fpmurphy
Sure it does. The break and continue statements are limited gotos. And are always translated to jumps in assembly language.
Ahhh, but the concept of GOTO a line number and/or label is alien to the shell.

Joke code that works, ;o)
(Note the smiley.)
Code:
#!/bin/sh
# goto
goto() { eval $1 ; }
label1() { echo "Test line 1." ; }
label2() { echo "Test line 2." ; }
label3() { echo "Test line 3." ; }
goto label1
goto label2
goto label3
goto label1
goto label2
goto label3

I know, I know, it is dreadful coding...
Results in CygWin:-
Code:
AMIGA:~> goto.sh
Test line 1.
Test line 2.
Test line 3.
Test line 1.
Test line 2.
Test line 3.
AMIGA:~> _

# 10  
Old 03-05-2014
I tend to stay away from functions unless they will be called more than once. I have the misfortune of trying to clean up after people who were "function happy" to the point that there are more functions than lines calling them with the called only running once.

Last edited by port43; 03-05-2014 at 12:57 PM.. Reason: poor English
This User Gave Thanks to port43 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

3. UNIX for Dummies Questions & Answers

Unix "look" Command "File too large" Error Message

I am trying to find lines in a text file larger than 3 Gb that start with a given string. My command looks like this: $ look "string" "/home/patrick/filename.txt" However, this gives me the following message: "look: /home/patrick/filename.txt: File too large" So, I have two... (14 Replies)
Discussion started by: shishong
14 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

6. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

7. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

8. UNIX for Dummies Questions & Answers

Unix "at" / "Cron" Command New Problem...Need help

Hi All, I am trying to schedule a one time job using the at command with the help of shell script for my project. The shell script should take a parameter as a command line argument from the at command itself. Is it possible to take a command line parameter for a shell script in the command... (3 Replies)
Discussion started by: Mohanraj
3 Replies

9. UNIX for Dummies Questions & Answers

Is there a "goto" command for AIX?

I have a korn script that needs to check for an empty file -- if the file is empty, I want the script to execute a cleanup step before exiting. Here's what I have: if ] then echo " Input file has no records -- skipping to step 9." goto cleanup fi ... ... (3 Replies)
Discussion started by: jderr
3 Replies

10. UNIX for Advanced & Expert Users

Commands on Digital Unix equivalent to for "top" and "sar" on other Unix flavour

Hi, We have a DEC Alpha 4100 Server with OSF1 Digital Unix 4.0. Can any one tell me, if there are any commands on this Unix which are equivalent to "top" and "sar" on HP-UX or Sun Solaris ? I am particularly interested in knowing the CPU Load, what process is running on which CPU, etc. ... (1 Reply)
Discussion started by: sameerdes
1 Replies
Login or Register to Ask a Question