views:

3350

answers:

3

I have a batch file like this:

java temptable %1 %2

I need the equivalent shell script for the above. I will pass the arguments to the shell script and that should be passed to temptable.

+8  A: 

For bash (which is one shell, but probably the most common in the Linux world), the equivalent is:

java temptable $1 $2

assuming there's no spaces in the arguments. If there are spaces, you should quote your arguments:

java temptable "$1" "$2"

You can also do:

java temptable $*

or:

java temptable "$@"

if you want all parameters passed through (again, that second one is equivalent to quoting each of the parameters: "$1" "$2" "$3" ...).

paxdiablo
i would suggest quoting the arguments.
jdigital
Done, thanks, @jd.
paxdiablo
That is also valid for sh and all derived shells, not just bash (AFAIK)
David Rodríguez - dribeas
I didn't want to speak for jsh/rc/rsh/tcsh/zsh/csh/ksh/bash/ash/sh/*sh and assume they were all the same.
paxdiablo
The sh/ksh/bash family are quite similar. I believe zsh to be closer to (ba|k)?sh than to the csh family.
Vatine
A: 

Here is an article, How to pass arguments to a shell script. It covers most about command line arguments

How to pass arguments to a shell script

kvmreddy
+1  A: 

!/bin/bash

# Call this script with at least 3 parameters, for example

sh scriptname 1 2 3

echo "first parameter is $1"
echo "Second parameter is $2"
echo "Third parameter is $3"
exit 0Output:[root@localhost ~]# sh parameters.sh 47 9 34f irst parameter is 47 Second parameter is 9 Third parameter is 34

vetri