0

我有一个从 shell 运行并下载文件并输出有关它下载的文件的一些信息的自定义程序?

    sh-3.1$ superdl -l username -p password filename
    Logging in...
    OK
    File: "filename"
    Size: "1100 bytes"
    Type: "text"
    Encryption: "RSA"
    Encoding: "utf-8"
    Done!
4

1 回答 1

1

这是在 bash 中执行的操作之一:

#!/bin/bash
while read -r var val
do
    [[ $var == Type: ]] && type="$val"
    [[ $var == Encryption: ]] && encryption="$val"
    [[ $var == Encoding: ]] && encoding="$val"
done < <(./superdl -l username -p password filename)

echo "$type $encryption $encoding"

输出:

text RSA utf-8

或使用案例陈述:

#!/bin/bash
while read -r var val
do
    case "$var" in
    Type: )
        type="$val" ;;
    Encryption: )
        encryption="$val" ;;
    Encoding: )
         encoding="$val" ;;
    esac
done < <(./superdl -l username -p password filename)

echo "$type $encryption $encoding"

关于问题中的编辑,没有什么真正改变。你可以做:

#!/bin/bash
for filename in "$@"
do

    while read -r var val
    do
        [[ $var == Type: ]] && type="$val"
        [[ $var == Encryption: ]] && encryption="$val"
        [[ $var == Encoding: ]] && encoding="$val"
    done < <(./superdl -l username -p password "$filename")

    echo "$type $encryption $encoding"
done
于 2013-09-18T13:29:06.177 回答