Solved

Executing File Options

Posted on 2006-11-08
1
279 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
ID: 17900438
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

919 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

14 Experts available now in Live!

Get 1:1 Help Now