【问题标题】:Convert my code from perl to shell script将我的代码从 perl 转换为 shell 脚本
【发布时间】:2020-01-18 05:04:22
【问题描述】:

请帮我解决这个问题。我在 Perl 中有代码,它在 shell 脚本中转换。

#!perl
my @a = (1..7000);
for(@a){
    my $curl=`curl -X GET http://localhost:9333/dir/assign?collection=chetan`;

    print $curl;
    $sub_string1 = substr($curl, 8,15); 
    print $sub_string1;
    $t='curl -X PUT -F file=@/home/user/test.txt http://172.17.0.4:8080/'.$sub_string1;
    print $t;
    my $curl=`$t`;
    #sleep(3)
    # print $curl
}

【问题讨论】:

  • 你试过什么?你有什么问题?请向我们展示您的代码。

标签: shell perl


【解决方案1】:

完全未经测试,实际上是逐行翻译(这里没有优化,即使有些东西可能写得更好):

for n in {1..7000}; do
    curl="$(curl -X GET http://localhost:9333/dir/assign?collection=chetan)"
    sub_string1="${curl:8:23}"
    t="curl -X PUT -F file=@/home/user/test.txt http://172.17.0.4:8080/$sub_string1";
    echo $t
    curl="$($t)"
done

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多