Sponsored Content
Top Forums Shell Programming and Scripting A dash to GOTO or a dash from GOTO, that is the question... Post 303038985 by MadeInGermany on Thursday 19th of September 2019 01:30:24 AM
Old 09-19-2019
Isn't line_number always equal to or greater than start_line?
It works because the output file is truncated at the right moment.

I would rather go for
Code:
goto()
{
    line_copy=
    while IFS='' read -r line
    do
        [ "$line" = "$1" ] && line_copy=1
        [ -n "$line_copy" ] && echo "$line"
    done < "$0" > /tmp/goto.tmp
    . /tmp/goto.tmp
}

Eventually swap the two lines in the loop, to omit the first line (then you do not need to prefix the lable with a nop).

Of course this is a hack. A function puts something on the "return" stack...
This User Gave Thanks to MadeInGermany For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to goto in ksh

Hi, I'm trying to use the goto in ksh but it does not appear to be a valid command. Is that only valid in csh? Anything similar in ksh that I can use? Appreciate any help you can provide. Thanks. geraldine (4 Replies)
Discussion started by: Geraldine
4 Replies

2. Shell Programming and Scripting

Use of GOTO statement in scripts

Hey Guys.. I just want to know how to use Goto statement in shell scripts. I know the basic use of statement. Goto Label The above statement will search for some label which must be defined in the script itself as: label: I tried these combinations but I didn't work out for me and I'm... (7 Replies)
Discussion started by: vikasduhan
7 Replies

3. Shell Programming and Scripting

goto statement

I have a test script for using goto statement but its not working. please help i tried both in linux and hp-ux it's not working please help #! /bin/ksh t=`ps -ef|grep ti.sh|grep -v grep` if ; then goto start else goto stop fi start: echo "start" stop: echo "stop" (5 Replies)
Discussion started by: Krrishv
5 Replies

4. UNIX for Dummies Questions & Answers

Stuck after typing goto

uname -a returns: SMP Tue May 17 17:52:23 EDT 2005 i686 athlon i386 GNU/Linux I have many aliases beginning with "goto" so... if I type goto and then hit return (oops) A goto prompt pops up and I cant exit from it(I tried MANY key seqs) The only way to exit is to kill the term window... (2 Replies)
Discussion started by: rairey
2 Replies

5. UNIX for Dummies Questions & Answers

dash after ampersant

Hi! I'm new in these forums and more or less new with Unix. So... here is the question: does anyone know where is redirected the output of a command when you put >&- after it? Does it means any standard file descriptor? Thanks! (2 Replies)
Discussion started by: csecnarf
2 Replies

6. Solaris

Goto last visted directory

Dear All, Can any one pls let me the command for how to goback to previous visited directory from the current working directory in SunOS ? In case of HP-UX; the same can be resolved through "cd -" command. Thanks in advance! Prasanth Babu. (6 Replies)
Discussion started by: prasanth_babu
6 Replies

7. Shell Programming and Scripting

remove dash

hi I am using ksh #A="abc-def" #typeset -u B="$A" #echo $B ABC-DEF how to remove the dash? i.e. ABCDEF? thank you (1 Reply)
Discussion started by: melanie_pfefer
1 Replies

8. Shell Programming and Scripting

Using A Goto Label?

Im trying to do something like this but I cant find any documentation. read X if then goto ThisLine fi OTHER CODE OTHER CODE Label: ThisLine echo "You entered 1" (5 Replies)
Discussion started by: Grizzly
5 Replies

9. Shell Programming and Scripting

Alternative for goto

#!/bin/sh label: echo sql poll v=`sqlplus -s <<! HR/HR set pages 0 echo off feed off select distinct status from emp where id=5; ! ` echo $v; echo it comes here after false if then echo if condition true sqlplus -l scott/tiger <<EOF select * from department; EXIT (2 Replies)
Discussion started by: kumaar1986
2 Replies

10. Ubuntu

Use of goto keyword in kernel programming

I have found many source files in the kernel using goto keyword instead of just doing the actual thing. For example: if(blah) goto x; -- -- -- -- -- x: return blah-blah Is there any specific reason for writing the code like this? The first thought that came to my mind is minimizing... (0 Replies)
Discussion started by: BHASKAR JUPUDI
0 Replies
getopt(3)						     Library Functions Manual							 getopt(3)

NAME
getopt - Gets flag letters from the argument vector LIBRARY
Standard C Library (libc) SYNOPSIS
#include <unistd.h> int getopt( int argc, char * const argv[], const char *optstring); extern char *optarg; extern int optind; extern int opterr; extern int optopt; STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: getopt(): XSH5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Specifies the number of parameters passed to the routine. Points to an array of argc pointers to argument strings. Specifies a string of recognized flag characters. If a character is followed by a : (colon), the flag is expected to take a parameter that may or may not be separated from it by white space. DESCRIPTION
The getopt() function parses argument lists. It returns the next flag character in the argv parameter list that matches a character in the optstring parameter. If that flag takes an argument, the getopt() function has the optarg variable point to the flag argument according to the following rules: If the flag is the last character pointed to by an argv element, optarg will contain argv's next element, and optind is incremented by 2. The getopt() function returns an error if the resulting optind is greater than or equal to argc. If the flag is not the last character, then the optarg variable points to the string after the flag character in the associated element of argv. The optind variable is incremented by 1. The optarg external variable is set to point to the start of the flag's parameter on return from the getopt() function. The getopt() function places the argv index of the next argument to be processed in optind. The optind variable is externally initialized to 1 before the first call to getopt() so that argv[0] is not processed. Error messages can be suppressed by providing a value of 0 (zero) as the opterr parameter. NOTES
[Tru64 UNIX] The external int optopt variable is set to the real flag found in the argv parameter. This is true whether the flag is in the optstring parameter or not. EXAMPLES
The following example shows a suggested way to use the getopt() function. #include <unistd.h> main(argc, argv) int argc; char *argv[]; #define ARGS "r:w:f:s" { int c, errflg = 0; int readers = 1, writers = 1; int freeBufs = 1; int doStats = FALSE; optarg = NULL; while (!errflg && ((c = getopt(argc, argv, ARGS)) != -1)) switch (c) { case 'r' : readers = atoi(optarg); break; case 'w' : writers = atoi(optarg); break; case 'f' : freeBufs = atoi(optarg); break; case 's' : doStats = TRUE; break; default : errflg++; } RETURN VALUES
Upon successful completion, the getopt() function returns the flag character that was detected. If the function encounters a flag that is not included in the optstring parameter, or if the : (colon) character is used incorrectly, the getopt() function prints an error message on stderr and returns a ? (question mark). If there is a missing flag, the getopt() function returns a : (colon) if optstring's first character is a : (colon), and a ? (question mark) otherwise. In addition, the getopt() function sets the optopt variable to the flag char- acter that caused one of these errors. The getopt() function also displays a diagnostic message if the application did not set the opterr variable to 0 (zero), and optstring's first character is not a : (colon). When all flags have been processed (that is, up to the first nonflag argument), the getopt() function returns a value of -1. The special flag -- (dash dash) can be used to delimit the end of the flags; -1 is returned, and the -- (dash dash) string is skipped. The getopt() function does not change optind, and also returns a value of -1, if one of the following occurs: The argv[optind] result is NULL. The *argv[optind] result is not the special - (dash) flag. The argv[optind] result points to the - (dash) string. The getopt() function does increment optind if the result of argv[optind] points to the -- (dash dash) string. RELATED INFORMATION
Commands: getopt(1) Standards: standards(5) delim off getopt(3)
All times are GMT -4. The time now is 08:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy