tags:

views:

94

answers:

4

I have a Linux bash script 'myshell'. I want it to read two dates as parameters, for example: myshell date1 date2. I am a Java programmer, but don't know how to write a script to get this done.

The rest of the script is like this:

sed "s/$date1/$date2/g" wlacd_stat.xml >tmp.xml
mv tmp.xml wlacd_stat.xml
+6  A: 

you use $1, $2 in your script eg

date1="$1"
date2="$2"
sed "s/$date1/$date2/g" wlacd_stat.xml >tmp.xml mv tmp.xml wlacd_stat.xml
ghostdog74
it works,thanks
chun
@chun, you also might want to wait for some time before accepting an answer even if it works for you. Perhaps other people could propose a better answer, but they may not even look at your question because something has already been accepted.
Pavel Shved
+1  A: 

$0 $1 $2

And so on will contain the script name, then the first and the second line argument.

Simone Margaritelli
+1  A: 

Bash arguments are named after their position.

Moreover, if you need to handle one argument after the other, you can shift them and always use $1:

while [ $# -gt 0 ]
do
    echo $1
    shift
done
mouviciel
+1  A: 

To iterate over the parameters, you can use this shorthand:

#!/bin/bash
for a
do
    echo $a
done

This form is the same as for a in "$@".

Dennis Williamson