Solved

Executing File Options

Posted on 2006-11-08
1
278 Views
Last Modified: 2010-04-21
Hey,

I would like to create an executable file with options, if I create a file named “dosomething” I would like to be able to pass in a parameter that would allow me to execute different things.  So… if I execute “./dosomething 1” I would be able to do different things.

… do some stuff for parameter of value 1
… do some stuff for parameter of value 2

How would I format the contents of the file? Is there an if statement or something of that kind?

Thanks,
Kate
0
Comment
Question by:kasiencja
1 Comment
 
LVL 6

Accepted Solution

by:
bira earned 500 total points
Comment Utility
yes, you can use case inside, as below


create the script dosomething with this contents:

case "$1" in
 1 ) echo "do option one"
       exit ;;
 2 ) echo "do option two"
       exit ;;
esac

chmod it 777 and call it:

 ./dosomething  <option>
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now