Erro de "variável indefinida" no script de shell no Sun Grid Engine

Erro de "variável indefinida" no script de shell no Sun Grid Engine

Eu tenho o seguinte script de envio do Sun Grid Engine:

#!/bin/sh
# sun grid engine cluster

# use current working directory
#$ -cwd

# merge error output into standard output stream
#$ -j yes
#$ -o generate_databases.log

# request to  cpu number
#$ -pe make 4

currentdir=`/bin/pwd`
echo "current working directory: $currentdir"

E aqui está minha saída

/home/eamorr/sge
currentdir: Undefined variable.

Como você pode ver, a variável 'currentdir' retorna indefinido.

Como consertar isto?

Responder1

Tem certeza que é bash? O operador backtick não é portátil. Existem várias maneiras de (possivelmente) corrigir isso:

  1. use #!/bin/bashna primeira linha para garantir que seja bash e nada mais
  2. evite os backticks: currentdir=$(pwd)oucurrentdir=$(/bin/pwd)
  3. ou até mais simplescurrentdir=$PWD

informação relacionada