xxxxxxxxxx
xxxxxxxxxx

Reputation: 41

How to pass arguments in remote ssh command

I am trying to run the shell script in the remote host , with this i also want to pass some arguments. my local host shell scripts is below

pwd
echo $0
echo $1
echo $2
echo thanku everyone!!

To run this script am using the command

ssh user@server 'ksh' < ./code

I want to pass arguments with this command. please clarify me in this..

Thanks in advance.

Upvotes: 0

Views: 4825

Answers (1)

ichramm
ichramm

Reputation: 6642

You can't pass parameters because you are starting ksh and using ./code as it's standard input.

But you can set an environment variable and then use it as command line, watch!

ichramm@wilderkrieger:~$ cat code
function run() {
    echo $1;
    echo $2;
}

run $COMMAND_LINE

ichramm@wilderkrieger:~$ ssh localhost 'COMMAND_LINE="hello world" ksh' < ./code
hello
world

Upvotes: 1

Related Questions