[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: bash and parameters



On Sat, Aug 14, 1999 at 12:50:20AM -0500, Lance Hoffmeyer wrote:
> When I create a shell script how do I pass parameters to it?  For
> example, if I want to create a directory based on a name I pass to the
> program with a shell script called mkmine the command would look like
> "mkmine Mydir" and this would create a directory called "Mydir"

> 
> would the script simply be mkdir %1 ?

No, that is a DOS batch script.  bash is really different, it uses $1 :)

> 
> if I wanted it to create a directory based on a name I give it and
> the current month would it be

> mkdir %1 & date %m  ? 

No again, this is DOS-speak.

A complete bash script to do what you want looks something like this:

------------------------------------------------------------------------
#! /bin/bash

mkdir $1`date +%m`
------------------------------------------------------------------------

The first line ensures the script is executed by bash.  The backquotes
around `date +%m` return the result of the date command as a string.  An
alternative way to get this result is

mkdir $1$(date +%m)

You make the
script executable with

chmod +x <script>

HTH,
Eric

-- 
 E.L. Meijer (tgakem@chem.tue.nl)
 Eindhoven Univ. of Technology
 Lab. for Catalysis and Inorg. Chem. (SKA)


Reply to: