0

我编写了一个输出用户选择的 URL 的小型 Rub​​y 脚本。我想将此 URL 嵌套到我的 Bash 脚本中,以便它直接输入 wget 部分,而不是强制用户复制和粘贴链接。当前代码如下:

>echo "Choose file to download"  
>./myscript.rb #  
>echo "Copy and Paste URL"  
>read answer  
>wget -O /myfile.zip "$answer"

对此的任何帮助将不胜感激。

编辑:

>"Choose file to download"
>18 obfuscated1.zip 891 Thu, 18 Apr 2013 16:13:05 GMT
>19 obfuscated2.zip 892 Fri, 19 Apr 2013 16:13:53 GMT
>20 obfuscated3.zip 893 Sat, 20 Apr 2013 16:13:16 GMT
>20
>http://s3-us.amazonaws.com/obfuscated3.zip/AWSAccessKeyId=/Expires=/Signature=

出于显而易见的原因,URL 在输出中被标记并在此处缩写。

4

1 回答 1

2

You could do it using command substitution:

answer=$(./myscript.rb)
wget -O /myfile.zip "$answer"

Update:

I haven't considered your script produces output other than the URL you are interested in.

Given that you can, at least:

  1. modify myscript.rb to emit the URL on the standard output and the other messages on the standard error. Then you should be able to use the solution above.

  2. run wget inside myscript.rb using the system Ruby method like this:

    # the url variable holds the URL chosen by the user
    system("wget -O /myfile.zip #{url}")
    
于 2013-04-24T15:41:11.103 回答