Manage starting point in shell script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Manage starting point in shell script.
# 1  
Old 08-28-2007
Data 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  
Old 08-28-2007
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  
Old 08-29-2007
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  
Old 08-29-2007
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 05:24 AM.. Reason: corrected a typo
# 5  
Old 08-29-2007
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  
Old 08-29-2007
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  
Old 08-29-2007
MySQL Manage starting point in shell script.

Smilie Perfect! Smilie
That's it.

Thanks a lot vino Smilie.

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

Regards.

Antonio.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell script help needed to manage FTP automation

Hi, I am very new in shell scripting. Have managed to prepare a script which will work to download data to local directory. But facing below problem. :wall: Please help me out. Thanks in advance. Problem: 1. I am unable to use delete command to delete data in the ftp location (I have... (2 Replies)
Discussion started by: ImranBD
2 Replies

2. Shell Programming and Scripting

Starting a C++ program from shell script

Hi, I have a little problem...I want to do the following things: Have my own little script that has 2/3 functions and starts a c++ application using some parameters. The problems appear when I start the c++ app using the shell script, the c++ takes over and after I ctrl+c the script... (0 Replies)
Discussion started by: valiadi
0 Replies

3. Shell Programming and Scripting

Shell script for Server Mount Point space check

Does anybody have anything I can use to help me out with this one? (4 Replies)
Discussion started by: lbone007
4 Replies

4. Shell Programming and Scripting

How to compare floating point numbers in shell script?

How can we compare 2 floating point numbers in SHELL script? (11 Replies)
Discussion started by: dearanik
11 Replies

5. Shell Programming and Scripting

Every nth line with different starting point

Hi every one, I am trying to generate different files from a column of numbers with the following format, as an example: main file(input) 1 2 3 . ... (19 Replies)
Discussion started by: nxp
19 Replies

6. Shell Programming and Scripting

shell script to remove all lines from a file before a line starting with pattern

hi,, i hav a file with many lines.i need to remove all lines before a line begginning with a specific pattern from the file because these lines are not required. Can u help me out with either a perl script or shell script example:- if file initially contains lines: a b c d .1.2 d e f... (2 Replies)
Discussion started by: raksha.s
2 Replies

7. Shell Programming and Scripting

facing problem in starting a process in background using shell script.

hey all, i am working on sun solaris machine and i want to start a process in background using shell script (actually i wanna start tomcat server using shell script). please dont tell me that append a & at last because this is not working in the shell script. i have also used nohup and... (8 Replies)
Discussion started by: dtomar
8 Replies

8. Shell Programming and Scripting

shell script for extracting out the shortest substring from the given starting and en

hi all, i need an urgent help for writing a shell script which will extract out and print a substring which is the shortest substring from the given string where first and last character of that substring will be given by the user. for e.g. if str="abcdpqracdpqaserd" now if the user gives 'a'... (18 Replies)
Discussion started by: pankajd
18 Replies

9. Shell Programming and Scripting

Help starting a simple shell script.

I've been sitting here for 6 hours typing out all kinds of different ridiculous(very pointless) shell scripts for a low-level UNIX class. I'm tired.. and want to go to bed :o Can somebody please help get me on the right path to starting this damn script? i'm useless after all these hours and... (2 Replies)
Discussion started by: dickmartin
2 Replies

10. Shell Programming and Scripting

How to manage multiple versions of a set of shell and SQL script utilities

Hi all --- I have the need to manage multiple versions of a set of utility scripts -- both shell and SQL and other .dat files. I am wondering if anyone out there knows of a good way to "PATH" to SQL and text files in a way similar to how PATH facilitates finding executables in a pre-specified... (2 Replies)
Discussion started by: DennisB
2 Replies
Login or Register to Ask a Question