Solved

Executing File Options

Posted on 2006-11-08
1
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

749 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