Solved

command %1 %2

Posted on 2002-07-24
3
201 Views
Last Modified: 2010-04-22
I want to make a script that can run diffent commands, like
command start

I started with the following code but now I am stuck.

Jeffeny

##### BEGIN ######

funct_param(){

# echo "$SWITCH"

if [ $SWITCH =  ]
then        
echo "Usage: command start | stop"
        exit 1
fi

if [ $SWITCH = start ]
then
        echo "start"
        exit 1
fi

if [ $SWITCH = stop ]
then
        echo "stop"
        exit 1
fi


}


##### MAIN ######

SWITCH=$1

       funct_param

##### END ######
0
Comment
Question by:harryv
  • 2
3 Comments
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 7175273
Try this:

#!/bin/ksh
##### BEGIN ######

funct_param(){

if [ "$SWITCH" = "" ]
then
       echo "Usage: command start | stop"
       return 1
elif [ $SWITCH = start ]
then
       echo "Execute: start"
       $SWITCH
       return 0
elif [ $SWITCH = stop ]
then
       echo "Execute: stop"
       $SWITCH
       return 0
fi
return 0
}


##### MAIN ######

SWITCH=$1

funct_param
if [ $? -ne 0 ]
then
       echo "Command not executed"
       exit 1
fi
exit 0
##### END ######
0
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 50 total points
ID: 7175285
Or....
#!/bin/ksh
##### BEGIN ######

funct_param(){

if [ "$SWITCH" = "" ]
then
       echo "Usage: command start | stop"
       return 1
elif [ $SWITCH = start ]
then
       echo "Execute: start"
       command $SWITCH
       return 0
elif [ $SWITCH = stop ]
then
       echo "Execute: stop"
       command $SWITCH
       return 0
fi
return 0
}


##### MAIN ######

SWITCH=$1

funct_param
if [ $? -ne 0 ]
then
       echo "Command $SWITCH not executed"
       exit 1
fi
exit 0
##### END ######
0
 

Author Comment

by:harryv
ID: 7175613
Thankx, it does work like I want it.

Jeffeny
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Downgrade centos 6.5 to 6.4? 7 1,039
how to run a command as a nologin user 7 350
centOS 7 GUI is now showing. 20 1,408
Help with a backup script in Linux 4 76
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

825 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