Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Executing File Options

Posted on 2006-11-08
1
Medium Priority
?
286 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
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 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.:

610 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