Bash: erro de sintaxe próximo ao token inesperado '('

1

eu sou um iniciante em coisas do Linux. Depois de algum tutorial eu usei o seguinte comando, que dividiu meu zinc.mol2 em 1000 arquivos chamados tmp.

cat zinc.mol2 | csplit -ftmp -n4 -ks - '%^@.TRIPOS.MOLECULE%' '/^@.TRIPOS.MOLECULE/' '{*}'

Agora eu tenho que usar o seguinte script, como por tutorial. Quando eu uso a primeira parte foreach f (tmp*) , recebo bash: syntax error near unexpected token '(' .

Alguém pode me guiar, como executar com sucesso o seguinte script?

# Rename the tmp file according to ZINC identifier
# Here the outline of how we do this:
#    1. extract ZINCn8 from the tmpNNNN file and set to variable
#    2. if the Zn8.mol2 file does not exist, the rename the tmpNNNN file

foreach f (tmp*)
echo $f
set zid = 'grep ZINC $f'
if !(-e "$zid".mol2) then
set filename = "$zid".mol2
else foreach n ('seq -w 1 99')
if !(-e "$zid"_"$n".mol2) then
set filename = "$zid"_"$n".mol2
break
endif
end
endif
mv -v $f $filename
end
    
por Ash 07.07.2016 / 03:46

1 resposta

3

O código que você está tentando executar parece estar na sintaxe do C-shell, ao invés da família Bourne de shells.

Você pode instalar e usar um shell C - por exemplo, o tcsh package

sudo apt-get install tcsh

csh

ou converta o código em seu bash equivalente: o seguinte não foi testado, pois não tenho acesso ao seu arquivo de entrada, mas deve estar próximo

for f in tmp*; do
  echo "$f"

  zid="$(grep ZINC "$f")"
  if [ -e "${zid}.mol2" ]; then
    filename="${zid}.mol2"
  else
    for n in {01..99}; do
      if [ -e "${zid}_${n}.mol2" ]; then
        filename="${zid}_${n}.mol2"
        break;
      fi
    done
  fi

  mv -v "$f" "$filename"

done
    
por steeldriver 07.07.2016 / 13:40