ich habe ein kleines script was eigentlich läuft solange ich "set -o nounset" weglasse, sobald ich "set -o nounset" benutze erhalte ich
als Fehlermeldung "./f_find_dependencies: line 115: result[@]: unbound variable" , wo liegt das Problem ?
Code: Alles auswählen
#!/bin/bash
###############################################################################
# #
# #
# #
# f_unload_extension FUNCTION #
# #
# try to find of a give extension all its dependencies #
# #
##############################################################################
set -o errtrace
# Trigger error when expanding unset variables. Same as `set -u'.
#
set -o nounset
#TinyCoreLinux Extensions Folder
TINYCOREEXTENSIONSFOLDER=/etc/sysconfig/tcedir/optional
#Root Directory
ROOTDIR=$(pwd)
#Buildding Directory
BUILDDIR=/mnt/xvda1/tmp
#////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function f_finddepfile() {
var_path_to_file=""
var_depfile_found=false
# if [ -f $TINYCOREEXTENSIONSFOLDER/$var_extension.tcz.dep ]; then
# var_path_to_file=$TINYCOREEXTENSIONSFOLDER
# var_depfile_found=true
# fi
}
#/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#///MAIN-FUNCTION.////////////////////////////////////////////////////////////////////////////////////////////////
#/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function f_find_dependencies () {
#set -x
declare -a EXTENSIONS # indexed array for the extensions
declare -a ANKER # indexed helper array for the extensions
EXTENSIONS=(mc)
#
#--- Check for required Stuff to run this script --------------------------
#
#echo "Check for required Stuff to run this script"
#
#[ ! -f /usr/local/tce.installed/util-linux ] && tce-load -wi util-linux
#[ ! -f /usr/local/tce.installed/bc ] && tce-load -wi bc
while [ $(echo ${#EXTENSIONS[@]}) -gt 0 ] ; do
for var_extension in ${EXTENSIONS[@]}; do
f_finddepfile
echo "START====$var_extension====>"
echo "var_depfile_found: $var_depfile_found $var_extension.tcz.dep"
if [ "$var_depfile_found" == "true" ]; then
#case
case "$var_path_to_file " in
/*)
for var_dep_file in $var_extension; do
while read line ; do
#check for empty line
[ -z "$line" ] && continue
echo "add depencie: ${line%%.*}"
#add extension to extensionsarray
EXTENSIONS+=(${line%%.*})
ANKER+="${var_extension}_@_${line%%.*} "
done < $var_path_to_file/$var_dep_file.tcz.dep;
#remove current array-element from array EXTENSIONS[0]
#http://stackoverflow.com/a/34199081
echo "<====removing array element: ${EXTENSIONS[0]} ";
EXTENSIONS_TEMP=("${EXTENSIONS[0]}")
result=("${EXTENSIONS[@]}")
for element in "${EXTENSIONS_TEMP[@]}"; do
result=(${result[@]/*${element}*/}) #/*${element}*/
done
#(re)set the array EXTENSIONS=( "${result[@]}" )
EXTENSIONS=( "${result[@]}" )
#echo -e "extensions@ ==ende=============================${EXTENSIONS[@]}\n"
done;;
esac
#echo -e "extensions@ ==ende=============================${EXTENSIONS[@]}\n"
#echo -e "extensions@ ==anker============================${ANKER[*]}\n"
fi
if [ "$var_depfile_found" == "false" ]; then
#remove current array-element from array EXTENSIONS[0]
#http://stackoverflow.com/a/34199081
echo "<====removing array element: ${EXTENSIONS[0]} ";
EXTENSIONS_TEMP=("${EXTENSIONS[0]}")
result=("${EXTENSIONS[@]}")
for element in "${EXTENSIONS_TEMP[@]}"; do
result=(${result[@]/*${element}*/}) #/*${element}*/
#[[ -z $result ]] && echo "$result" || echo "eeeemmmmppptttyyyyy"
done
set -x
#(re)set the array EXTENSIONS=( "${result[@]}" )
#[[ -z $result ]] && echo "$result" || echo "eeeemmmmppptttyyyyy"
EXTENSIONS=( "${result[@]}" )
#EXTENSIONS[${#EXTENSIONS[*]}]
#echo -e "extensions@ ==ende=============================${EXTENSIONS[@]}\n"
fi
done
done
echo -e "extensions@ ==ende=============================${EXTENSIONS[@]}\n"
echo -e "extensions@ ==anker============================${ANKER[*]}\n"
}
#}
f_find_dependencies