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

22,731

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

#!/bin/bash
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:
22,731

Related videos on Youtube

coderlearner
Author by

coderlearner

Updated on September 17, 2022

Comments

  • coderlearner
    coderlearner over 1 year

    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
  • Martin
    Martin over 13 years
    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.