2

我正忙于编写一个可以从 FTP 下载一些文件的脚本,我想要一个 select 语句来提供 ftp 子目录中的目录。但也提供一个选项下载所有这一切都应该发生在底部的@$DNAtype。有人有什么想法吗?

我的代码是:(对不起荷兰评论)

#!/bin/bash/
#16-03-2012
#Sander van der Zeeuw s1040176

#Variabele om de ftp aan te kunnen roepen
var='ftp://ftp.ensembl.org/pub/release-66/fasta/'
#Hier word de lijst met beschikbare organisme binnengehaald via de functie curl.
# curl is te installeren via de terminal met het command sudo apt-get install curl
lijst=`curl $var | awk '{print $NF}'`

echo "de keuze 0 selecteert alles"

#hier wordt een directory aangemaakt om de files in weg te schrijven
mkdir -p dnaenpep
cd dnaenpep



#Hier wordt een keuze menu gecreeerd om het juiste organisme te kiezen.
select specie in $lijst
do
    break
done
echo "Uw keuze is:" $specie


#Hier wordt de keuze "0" ingebouwd. Zodat alle genomen gedownload worden.
if [ "$specie" == "" ]
then
    for i in $lijst
    do
        namen=$(curl $var$i/dna/ | awk '{print($NF)}')
        for files in $namen; do curl $var$i/dna/$files -o $files
                    curl $var$i/pep/$files -o $files
        done 
    done
fi

echo "de keuze 0 selecteert alles"

#Wanneer de loop niet uitgevoerd wordt, zal via nog een select statement de gekozen worden #welk DNA je van de ftp wil downloaden. 
lijst2=`curl $var$specie/ | awk '{print $9}'`
echo $lijst2

select dnatype in $lijst2
do
    break
done
echo "uw keuze is:" $dnatype

if [$dnatype == ""]
then
    for i in $dnatype
    do
        wget -O DNAtype "$var$specie/dna/"
        wget -O DNAtype "$var$specie/pep/"
    done
fi

#Hier worden de files die in $dnatype gemaakt worden gedownload.
wget -O DNAtype "$var$specie/$dnatype/"

cat DNAtype | egrep "=" | tr '"' '\n' | sort | grep ^"ftp" |grep gz > Downlist.txt
wget -c -i  Downlist.txt

exit
4

1 回答 1

1

select您的 select 语句应该使用一个数组,您可以在数组中添加其他项目或在语句中的数组名称之后添加它们。

lijst2=($(curl "$var$specie/" | awk '{print $9}')
lijst2+=("Another option" "Additional option" "Download all")
echo "${lijst2[@]}"

select dnatype in "${lijst2[@]}"
do
    break
done
echo "uw keuze is: $dnatype"

或者

lijst2=($(curl "$var$specie/" | awk '{print $9}')
echo "${lijst2[@]}"

select dnatype in "${lijst2[@]}" "Another option" "Additional option" "Download all"

do
    break
done
echo "uw keuze is: $dnatype"

您选择哪个取决于您是否想要在数组中添加选项。

要全部下载,只需遍历数组(因此您可能希望使用第二个版本,因此您不必跳过“全部下载”,例如,因为它不是文件名。

补充笔记:

Use $() instead of backticks for command substitution.

This statement if [$dnatype == ""] needs spaces: if [ $dnatype == "" ].

Quote all your variables when they are expanded. You have done this in some places, but not others.

Your long pipeline near the end can almost certainly be simplified. Without seeing example data I could only guess how.

于 2012-07-01T11:21:14.820 回答