2017-04-11 45 views
0
#!/bin/bash 

#cicle 1 
for fname in *.xlsx *csv 
    do 
      dname=${fname%.*} 

      [[ -d $dname ]] || mkdir "$dname" 
      mv "$fname" "$dname" 
    done 

    # In questo ciclo per ogni gene entra nella cartella e lancia i programmi di getChromosomicPositions.sh per avere 
    # le posizioni nel genoma, e getHapolotipeStings.sh per avere le varianti 

#cicle 2 
    for geni in */; do 
      cd $geni 
      z=$(tail -n 1 *.csv | tr ';' "\n" | wc -l) # geuarda nel file csv quante colonne ci sono e trasferisce il riusltato al programma getChromosomicPositions 
      cd .. 
      cp getHGSVposHG19.sh $geni 
      cp getChromosomicPositions.sh $geni 
      cp getHaplotypeStrings.sh $geni 
      cd $geni 
      pippo=$(basename $(pwd)) 
      export z 
      export pippo 
      ./getChromosomicPositions.sh *.csv 
      export z 
      ./getHaplotypeStrings.sh *.csv 
      cd .. 
    done 

我有這個腳本2 cicle,如何進來只能與腳本bash的新目錄

我想是在cicle 2只爲創建新的目錄做compilate程序的工作在cicle 1

我的意思是:

我有這個文件的主要目錄:

pippo.xlsx pippo.csv

caio.xlsx caio.csv

topolino(目錄)

敏妮(目錄)

paperino(目錄)

在cicle 1使directorys皮波

和卡歐

我希望在cicle 2我想要在新目錄(pippo,caio)中出現,並將cicle的所有工作僅限於新目錄pippo和caio,而不是舊目錄topolino ,minny和paperino。

我該怎麼做?

+0

請整理你的腳本的縮進的問題。順便說一下,「cicle」是一個「循環」,或在這種情況下,一個「循環」,在英語中。 –

+0

我的意思是說對不起,這兩個對 –

回答

0

你可以創建一個數組與新創建的目錄,然後在這個數組循環:

#!/bin/bash 
set -o errexit # Exit the script in case of error 

# Pre-declare and empty array. 
declare -a new_directories; 

# Save other scripts path for later use. 
getHGSVposHG19="${pwd}/getHGSVposHG19.sh" 
getChromosomicPositions="${pwd}/getChromosomicPositions.sh" 
getHaplotypeStrings="${pwd}/getHaplotypeStrings.sh" 

# Create missing directories 
for fname in *.xlsx *csv 
do 
    dname=${fname%.*} 
    if [ ! -d $dname ] 
    then 
     mkdir "$dname"; 
     new_directories+=("${dname}"); 
    fi 

    mv "$fname" "$dname"; 
done 

# Initialize only new directories 
for geni in "${new_directories[@]}" 
do 
    pushd "${geni}"; # Add to directory stack 

    export pippo="$(basename $(pwd))"; 
    export z=$(tail -n 1 *.csv | tr ';' "\n" | wc -l) 

    "${getChromosomicPositions}" *.csv; 
    export z; # Is the previous script modifying z? 

    "${getHaplotypeStrings}" *.csv; 
    popd; #Remove from directory stack 
done 

我也冒昧地清理你的腳本一點,因爲我不能運行它是,它可能有一些拼寫錯誤/缺陷......


What is pushd and popd?