【问题标题】:How can I convert this VBS script to Bash?如何将此 VBS 脚本转换为 Bash?
【发布时间】:2017-09-28 04:03:15
【问题描述】:

我在 VBS 中有这段代码,需要在 Bash 中重建。这是我必须转换的更大脚本的 sn-p。有人可以帮我解决这个问题吗?

在过去的两天里,我阅读了很多关于 Bash 的文档,我一直在编写更大的脚本,但仍然不确定如何去做。我的同事/培训师基本上把这个递给了我,并告诉我使用谷歌来学习 Bash 来做到这一点。我觉得同样重要的是要注意我对 VBScript 也不熟悉。

Function Build_Param_Array()
    Set objFSO = WScript.CreateObject("Scripting.Filesystemobject")
    Set ReadFile = objFSO.OpenTextFile("Param_List.txt")
    While Not ReadFile.AtEndOfStream
        thisline = ReadFile.ReadLine
        Pcount = Pcount + 1
        ReDim preserve arrParam(Pcount)
        If Not Right(thisline,1) = "|" Then thisline = thisline & "|"
        arrParam(Pcount) = thisline
    Wend
End Function

【问题讨论】:

    标签: bash vbscript


    【解决方案1】:

    不是 vbs 大师,但为了一般猜测,它看起来像是读取 Param_List.txt,确保每行以管道字符结尾,然后将其推送到数组 (arrParam)。

    typeset -a arrParam       # declare an array
    while read l              # read each line from stdin into l
    do arrParam+=("${l%|}|")  # push the line onto the array, assuring a |
    done < Param_List.txt     # put the file on the loop's stdin
    

    $l 是读取的行。 ${l%|} 是读取的行,删除了任何管道作为最后一个字符;因此"${l%|}|" 明确删除了一个管道如果有一个,然后添加一个,无论是否删除。

    【讨论】:

      猜你喜欢
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多