The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
facing problem in starting a process in background using shell script. dtomar Shell Programming and Scripting 8 04-17-2008 08:11 AM
shell script for extracting out the shortest substring from the given starting and en pankajd Shell Programming and Scripting 18 03-10-2008 06:20 AM
Trying to manage an inherited Ksh script ajcannon Shell Programming and Scripting 1 08-15-2007 06:54 AM
Help starting a simple shell script. dickmartin Shell Programming and Scripting 2 07-29-2004 09:02 AM
How to manage multiple versions of a set of shell and SQL script utilities DennisB Shell Programming and Scripting 2 06-23-2004 08:13 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-28-2007
ai_dba ai_dba is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 3
Unhappy Manage starting point in shell script.

Hi,
I'd like to run a script with an optional starting point.
Meaning that if no parameter for the script => Do everything, otherwise start from the point specified in the parameter and continue till the end.

I thought of using the "case ..." but I have no result.
Script:
# ---------------
START_POINT=$1
if [ "$START_POINT" = "" ]
then
START_POINT="a"
fi
echo ">$START_POINT<"
case $START_POINT in
"a") echo "Running >a<!";;
"b") echo "Running >b<!";;
"c") echo "Running >c<!";;
"d") echo "Running >d<!";;
default) echo "Wrong value for starting point";;
esac
return
# ---------------
result expected:
> script [nothing]
Running >a<!
Running >b<!
Running >c<!
Running >d<!

> script c
Running >c<!
Running >d<!

> script k
Wrong value for starting point

Please provide some help.
Thanks in advance.
Regards!
  #2 (permalink)  
Old 08-28-2007
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
Alternatively, you can write functions to do specific tasks and then call them as per needed. If no arguements are passed to the script, call all the functions.
  #3 (permalink)  
Old 08-29-2007
ai_dba ai_dba is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 3
Manage starting point in shell script.

Yes, that'a an alternative.
My main issue is to manage the starting point in the script, not running every thing.

Thanks.
  #4 (permalink)  
Old 08-29-2007
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
if you are using tcsh, then you can take help of goto to do what you want. bash and ksh does not support goto.

Also, have a look at this (that person might have solved his problem without using goto)

Last edited by Yogesh Sawant; 08-29-2007 at 04:24 AM.. Reason: corrected a typo
  #5 (permalink)  
Old 08-29-2007
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
It's much more simpler if you use numbers as starting points:

Code:
START_POINT="$1"

if [ ! "$START_POINT" ]; then START_POINT=0; fi

if [ "$START_POINT" -le 10 ]; then echo "Running 10!"; fi
if [ "$START_POINT" -le 20 ]; then echo "Running 20!"; fi
if [ "$START_POINT" -le 30 ]; then echo "Running 30!"; fi
Then you specifiy a parameter and, if the number is lesser than the execution step, the code will be executed.
  #6 (permalink)  
Old 08-29-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Put the case-esac construct in a while loop.

Code:
[/tmp]$ cat test.ksh
#! /bin/ksh
#

while :
do
    case $1 in
        "") set -- a ;;
        "a") echo "a" ; set -- b ;;
        "b") echo "b" ; set -- c ;;
        "c") echo "c" ; set -- d ;;
        "d") echo "d" ; break ;;
        *) echo "Wrong" ; break ;;
    esac
done
[/tmp]$ ./test.ksh
a
b
c
d
[/tmp]$ ./test.ksh a
a
b
c
d
[/tmp]$ ./test.ksh c
c
d
[/tmp]$ ./test.ksh d
d
[/tmp]$ ./test.ksh z
Wrong
[/tmp]$ ./test.ksh abcd
Wrong
[/tmp]$
  #7 (permalink)  
Old 08-29-2007
ai_dba ai_dba is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 3
Thumbs up Manage starting point in shell script.

Perfect!
That's it.

Thanks a lot vino .

Thanks also to others, I will use some answers for something else .

Regards.

Antonio.
Sponsored Links
Closed Thread

Bookmarks

Tags
shell script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 06:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0