【问题标题】:how i can pass a file directory (path) as parameter?我如何将文件目录(路径)作为参数传递?
【发布时间】:2011-04-20 16:15:41
【问题描述】:

我如何将文件目录(路径)作为参数传递给 1.windows操作系统中的批处理文件 2. unix操作系统中的bash文件

【问题讨论】:

    标签: windows bash unix command-line batch-file


    【解决方案1】:
    Batch files can only handle parameters %0 to %9
    
    %0 is the program name as it was called,
    %1 is the first command line parameter,
    %2 is the second command line parameter,
    and so on till %9.
    

    用于批量检查@http://www.robvanderwoude.com/parameters.php

    对于shell脚本检查@http://docsrv.sco.com:507/en/OSUserG/_Passing_to_shell_script.html

    【讨论】:

      【解决方案2】:

      对于 Windows 批处理文件,您可以使用 %1%2%3 等)。使用 Bash,您可以使用 $1 ($2,$3...)。

      【讨论】:

        【解决方案3】:

        1) 到 Windows 批处理文件:

        script.bat C:\some\path
        

        要访问脚本中的路径,请使用 %1:

        echo %1
        

        2) 到 bash shell 脚本:

        script.sh /some/path
        

        要访问脚本中的路径,请使用 $1:

        echo $1
        

        【讨论】:

          【解决方案4】:

          在 bash 中,您使用 $1 来获取第一个参数。您是说它必须是目录的路径,因此您可能需要尝试以下操作:

          test -d $1 && echo "Directory exists"
          

          【讨论】:

            猜你喜欢
            • 2013-01-25
            • 2013-02-26
            • 2014-05-15
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2020-07-27
            • 1970-01-01
            相关资源
            最近更新 更多