Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Unix shell script question (goto - label)

Posted on 2003-10-29
Medium Priority
Last Modified: 2013-12-26
I am a novice shell script programmer, so be gentle!

Currently I have a automated process that uses about 10 separate Bourne shell scripts... One will execute, then fire off the next and so forth.
I want to consolidate the scripts into one, but I need to use some type of "goto" command to a label inside the script. I did not find any "goto" command in my Unix Shell programming book. I know that the "csh" uses "goto", but I was told not to use "csh".

Any suggestions?
Question by:rlburris
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 38

Accepted Solution

yuzh earned 1000 total points
ID: 9647955
If you want to merge all the scripts in one piece, define each script as a function of your
main script.
just make sure that you declear the fuction at the beginning of your script


a litter script:

# log something to a log file
echo "$1" >>$LOGFILE 2>&1

Now we, write a main script and modify the above script as a function.


# VAR declarations


# Functions

Log ()
  echo "$1" >>$LOGFILE 2>&1

# start of the main script
# do some thing

# use the function
Log "Subject: SUCCESS!: ${DAY} Backup log for SQL Server"

# do other things



Hope that it can help.

Author Comment

ID: 9648079
      Please explain (break down) the following command:
echo "$1" >> $LOGFILE 2>&1

Also when you use the function Log in your example... Does "Subject:SUCCESS!" writes to the LOGFILE?

LVL 38

Expert Comment

ID: 9648170
echo "$1" >> $LOGFILE

willl write "Subject: SUCCESS!: ${DAY} Backup log for SQL Server" to $LOGFILE
in this case is /var/log/mylog (I defined it before the function)

echo "$1" >> $LOGFILE 2>&1

will write "Subject: SUCCESS!: ${DAY} Backup log for SQL Server" + any
error message to the login file (I redirect stderr to stdin)

Author Comment

ID: 9648468
Thanks yuzh!!!
LVL 38

Expert Comment

ID: 9648474
You are welcome.


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question