0

I have written a bash script. It is launched like this:

./myscript.sh $IP COMMAND-FILE

In COMMAND-FILE I give commands which I have to run on remote server. But now I have to use another script in COMMAND-FILE, like this:

yesSkip.sh $IP

My question is that how can I give input of IP which is showing in above line.

  • Could you please clarify what you mean by 'giving input of IP'? Do you want to call this within the myscript.sh and pass the same arguments to the second script? – Erathiel Mar 30 '15 at 14:41
1

You want to know how to use the $IP from the command line as a parameter to another part of your script? This is a little like Bash 101 (Bash for Beginners), and it sounds like you could be recommended to spend some time going through a scripting tutorial.

However, to answer your question directly, each parameter is available as a numbered variable, $1, $2, and so on. So you can (re)use the first parameter like this:

yesSkip.sh "$1"

If you're really keen, at the top of your script assign the parameters to variables and use those (it helps with documentation of the code):

#!/bin/bash
#
IP="$1"
COMMANDFILE="$2"

...later...

yesSkip.sh "$IP"

Not the answer you're looking for? Browse other questions tagged or ask your own question.