Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want run an .sh file which take an argument in a Linux machine. I'm using plink.exe to execute this .sh file from a windows machine. But I don't know what to write in the batch file in order to run plink.exe which in turn executes the .sh file and this file arguement.

I have written following batch command:

@echo off  
start C:\Users\Prateek\Desktop\PLINK.EXE -ssh -P 22 user@host -pw password sh -x  "/home/user/"

On executing it, I get:

+ echo ''  

+ echo 'Enter partner id'  
Enter partner id  
+ read pid  

Actually 'Enter partner id' is the argument, which I need to pass.

share|improve this question
This is confusing. Could you copy-paste the complete terminal session? When you say you need to pass an argument, do you mean a command line argument or do you mean it should be supplied as input to the command? – Eroen Sep 18 '12 at 14:16
Using username "userPrateek". Debian GNU/Linux 4.0 wpdevprateek ssh-pty Linux wpdevprateek #1 SMP Wed Nov 11 12:01:55 UTC 2009 i 686 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Tue Sep 18 09:32:43 2012 from ←]0;userPrateek@wpdevprateek: ~userPrateek@wpdevprateek:~$ – Prateek Sep 18 '12 at 14:24
Above is complete session terminal, so in default directory there is /home/user/ Which will ask string as argument. So i need to write all this process from starting plink.exe then, executing file with the argument which it take as command line argument in batch file(.bat). – Prateek Sep 18 '12 at 14:30
up vote 1 down vote accepted

I still don't really understand what you want, but I'll make some assumptions, then we can see how it goes ;-) Unfortunately, I don't have a Windows shell readily available either, so my Batch foo might be a bit off, especially with respect to quoting, doubly so if things contain spaces. Edits are welcome.

  1. I understand that you want to supply a command line argument to your batch file. This will then be available inside the batch file as %1.

  2. I assume the string obtained in the previous paragraph should be supplied to the UNIX shell script as input. This can (for instance) be done in the login shell on the Linux box by piping an echo command to the second shell.

Try the following modification:

start C:\Users\Prateek\Desktop\PLINK.EXE -ssh -P 22 user@host -pw password echo %1 ^| sh -x  "/home/user/"

If invocated as mybatch.bat SomeText, it should run the following in a shell on the remote host:

echo SomeText | sh -x /home/user/

which runs and makes it think someone typed in SomeText at a keyboard for it.

share|improve this answer
pardon me Eroen for not putting my question clearly, but your assumption is really correct...great...:-)..that helped me..thanks much.... – Prateek Sep 18 '12 at 17:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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