ENH:foamJob: handling of quotes (from Mantis)

This commit is contained in:
mattijs 2013-12-04 15:48:32 +00:00
parent a7799adeb8
commit a5ebecbd3a

View File

@ -3,7 +3,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
# \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
@ -50,6 +50,28 @@ USAGE
exit 1
}
#for being able to echo strings that have single quotes
echoArgs() {
addSpace=""
for stringItem in "$@"; do
echo -n "${addSpace}"
if [ "${stringItem##* }" = "$stringItem" ]
then
echo -n "$stringItem"
addSpace=" "
else
echo -n "'$stringItem'"
addSpace=" "
fi
done
unset stringItem addSpace
}
unset version
# replacement for possibly buggy 'which'
@ -217,11 +239,11 @@ then
#
if [ "$screenOpt" = true ]
then
echo "Executing: $mpirun $mpiopts $APPLICATION $@ -parallel | tee log"
$mpirun $mpiopts $APPLICATION $@ -parallel | tee log
echo "Executing: $mpirun $mpiopts $APPLICATION $(echoArgs "$@") -parallel | tee log"
$mpirun $mpiopts $APPLICATION "$@" -parallel | tee log
else
echo "Executing: $mpirun $mpiopts $APPLICATION $@ -parallel > log 2>&1"
$mpirun $mpiopts $APPLICATION $@ -parallel > log 2>&1 &
echo "Executing: $mpirun $mpiopts $APPLICATION $(echoArgs "$@") -parallel > log 2>&1"
$mpirun $mpiopts $APPLICATION "$@" -parallel > log 2>&1 &
fi
else
@ -230,12 +252,12 @@ else
#
if [ "$screenOpt" = true ]
then
echo "Executing: $APPLICATION $@ | tee log &"
$APPLICATION $@ | tee log &
echo "Executing: $APPLICATION $(echoArgs "$@") | tee log &"
$APPLICATION "$@" | tee log &
wait $!
else
echo "Executing: $APPLICATION $@ > log 2>&1 &"
$APPLICATION $@ > log 2>&1 &
echo "Executing: $APPLICATION $(echoArgs "$@") > log 2>&1 &"
$APPLICATION "$@" > log 2>&1 &
fi
fi