Erro de sintaxe: “(” inesperado - terminal do Ubuntu

-2

Estou executando o script a seguir, que começa com o #!/bin/bash

#!/bin/bash
#

############################################
# User Configuration
############################################

# adapt this path to your needs
gptPath="/usr/local/snap6/bin/gpt.sh"

############################################
# Command line handling
############################################

# first parameter is a path to the graph xml
graphXmlPath="$1"

# second parameter is a path to a parameter file
parameterFilePath="$2"

# use third parameter for path to source products
sourceDirectory="$3"

# use fourth parameter for path to target products
targetDirectory="$4"

# the fifth parameter is a file prefix for the target product name, typically indicating the type of processing
targetFilePrefix="$5"


############################################
# Helper functions
############################################

# Borrowed from http://www.linuxjournal.com/content/normalizing-path-names-bash
function normalizePath() {
    # Remove all /./ sequences.
    local path="${1//\/.\//\/}"

    # Remove first dir/.. sequence.
    local npath=$(echo "$path" | sed -e 's;[^/][^/]*/\.\./;;')

    # Remove remaining dir/.. sequence.
    while [[ "$npath" != "$path" ]]; do
        path="$npath"
        npath=$(echo "$path" | sed -e 's;[^/][^/]*/\.\./;;')
    done
    echo "$path"
}

getAbsolutePath() {
    file="$1"

    if [ "${file:0:1}" = "/" ]; then
        # already absolute
        echo "$file"
        return
    fi

    absfile="$(pwd)/${file}"
    absfile="$(normalizePath "${absfile}")"
    echo "${absfile}"
}

removeExtension() {
    file="$1"

    echo "$(echo "$file" | sed -r 's/\.[^\.]*$//')"
}


############################################
# Main processing
############################################

# Create the target directory
mkdir -p "${targetDirectory}"

IFS=$'\n'
for F in $(ls -1 "${sourceDirectory}"/S3*.SEN3/xfdumanifest.xml); do
  sourceFile="$(getAbsolutePath "$F")"
  targetFile="${targetDirectory}/${targetFilePrefix}_$(removeExtension "${F}").dim"
  procCmd="${gptPath}" "${graphXmlPath}" "/-e -p /" "${parameterFilePath}" "/ -t /" "${targetFile}" "${sourceFile}"
  "${procCmd}"
done

Howevern, ao executar o scritp com

sh /shared/Downloads/Chipre/processDataset_V4.bash /shared/Downloads/Chipre/myGraph_v3_for_GPT_v2_2.xml variables.properties "/shared/Downloads/Chipre/June" "/shared/Downloads/Chipre/GPT/June" ndvi

Eu recebo o erro:

/shared/Downloads/Chipre/processDataset_V4.bash: 36: /shared/Downloads/Chipre/processDataset_V4.bash: Syntax error: "(" unexpected

Eu tentei as soluções explicadas em este post mas não está funcionando. Alguma idéia?

EDITAR

ls -l /shared/Downloads/Chipre

total 64
drwxr-xr-x  3 rus rus 4096 Mar  1 13:30 GPT
drwxr-xr-x  9 rus rus 4096 Feb 22 08:15 July
drwxr-xr-x 10 rus rus 4096 Mar  1 13:28 June
drwxr-xr-x  9 rus rus 4096 Feb 21 12:22 May
drwxr-xr-x  5 rus rus 4096 Mar  1 13:28 graph
-rw-r--r--  1 rus rus 2635 Feb 16 08:33 myGraph_v3.xml
-rw-r--r--  1 rus rus 3205 Feb 27 14:34 myGraph_v3_for_GPT_v2.xml
-rw-r--r--  1 rus rus 2518 Feb 28 08:28 myGraph_v3_for_GPT_v2_1.xml
-rwxr-xr-x  1 rus rus 1573 Feb 28 08:37 myGraph_v3_for_GPT_v2_2.xml
-rwxr-xr-x  1 rus rus 2155 Mar  1 13:45 processDataset_V4.bash
-rw-r--r--  1 rus rus 2155 Mar  1 13:45 processDataset_V4.sh
-rw-r--r--  1 rus rus 2157 Mar  1 13:25 processDataset_V4_backup.bash
-rw-r--r--  1 rus rus 8711 Feb 28 08:06 subset_WKT.odt
-rwxr-xr-x  1 rus rus  780 Feb 28 08:28 variables.properties
  • EDITAR

Depois de remover function do scritp, o erro não aparece mais, mas agora estou recebendo:

/shared/Downloads/Chipre/processDataset_V4.bash: 54: /shared/Downloads/Chipre/processDataset_V4.bash: Bad substitution
/shared/Downloads/Chipre/myGraph_v3_for_GPT_v2_2.xml: 2: /shared/Downloads/Chipre/myGraph_v3_for_GPT_v2_2.xml: Syntax error: newline unexpected
/shared/Downloads/Chipre/processDataset_V4.bash: 84: /shared/Downloads/Chipre/processDataset_V4.bash: : Permission denied
    
por GCGM 01.03.2018 / 15:15

1 resposta

1

A questão é provável:

function normalizePath() {

A alternativa portátil é:

normalizePath() {

No entanto, existem muitos outros bashisms em seu script, então você precisa consertar todos eles ou apenas usar bash em vez de qualquer link sh em seu sistema.

bash /shared/Downloads/Chipre/processDataset_V4.bash /shared/Downloads/Chipre/myGraph_v3_for_GPT_v2_2.xml variables.properties "/shared/Downloads/Chipre/June" "/shared/Downloads/Chipre/GPT/June" ndvi

ou apenas ligue como está:

/shared/Downloads/Chipre/processDataset_V4.bash /shared/Downloads/Chipre/myGraph_v3_for_GPT_v2_2.xml variables.properties "/shared/Downloads/Chipre/June" "/shared/Downloads/Chipre/GPT/June" ndvi
    
por jlliagre 01.03.2018 / 15:52