Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

how i can pass a file directory (path) as parameter to

  1. batch file in windows operating system
  2. bash file in unix operating system
share|improve this question

1 Answer 1

up vote 3 down vote accepted

To pass a directory to a windows batch file you put it on the command line of the batch file. When working with paths it is a good thing to put "" around them as they may contain spaces etc e.g.

c:\temp\batchfile.bat "c:\program files"

to reference the command line arguments in your batch file use %1 %2 and so on.

If for example you had a simple batch file (c:\temp\b.bat) like this

dir %1
exit /b 3

and you called it as above, you would get a directory listing of c:\program files.

I'm going to guess now that what you want to do is pass a windows path to a unix script and then get the unix script to run a batch file on windows and pass the windows path supplied to the windows batch file.

Similarly to windows you pass the arguments to a bash script on the command line. You need to enclose the path in "". bash will attempt to interpret any special characters in your command line arguments so you need to enclose the path argument in '' too e.g.

bashscript '"c:\program files"'

To reference the command line arguments in bash use $1 $2 etc.

If your bash script was

ssh -l admin host 'cmd /c c:/temp/b.bat ' $1

then you would get a directory listing of c:\program files and 3 would be returned to $?.

share|improve this answer
Note that the double quotes will be part of the %1 parameter - which is a good thing or a bad thing, depending on what you want to do with it. –  Martin Oct 5 '10 at 8:39

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.