samedi 11 septembre 2021

How can I call an external bash function with parameters in an if condition

I am trying to call an external bash script in an if condition in my main script. The code of the external script IsArchive:

#!/bin/bash
STR="$1"

if [[ "$STR" ==  *".zip"* ]] || [[ "$STR" ==  *".iso"* ]] || [[ "$STR" ==  *".tar.gxz"* ]] || [[ "$STR" ==  *".tar.gx"* ]] || [[ "$STR" ==  *".tar.bz2"* ]] || \
   [[ "$STR" ==  *".tar.gz"* ]] || [[ "$STR" ==  *".tar.xz"* ]] || [[ "$STR" ==  *".tgz"* ]] || [[ "$STR" ==  *".tbz2"* ]]
then
        return 0
else 
        return 1
fi

and I try calling it in my main script as:

elif [[ $Option = "2" ]]
then
                if IsArchive "$SourcePath";
                then
                        less -1Ras "$SourcePath" | tee "$OutputFilePath"

                #if file is not an archive
                else
                        ls -1Rasl "$SourcePath" | tee "$OutputFilePath"
                fi

when I execute the main script I receive the Error: ./script: line 61: IsArchive: command not found

Aucun commentaire:

Enregistrer un commentaire