Shell Script: Unterschied zwischen den Versionen
Aus MeinWiki
K (→Funktion) |
|||
| Zeile 14: | Zeile 14: | ||
echo $(date "+%y%m%d-%H%M%S")' '$1 >> $2 | echo $(date "+%y%m%d-%H%M%S")' '$1 >> $2 | ||
} | } | ||
| + | *change from upper to lower char | ||
| + | # change from upper to lower char | ||
| + | # $1 Variable to change | ||
| + | # $2 Logfiledestionation | ||
| + | LowerChar () | ||
| + | { | ||
| + | WriteLog 'LowerChar '$1 $2 | ||
| + | local myResult=`echo $1 | tr 'A-Z' 'a-z'` | ||
| + | echo "$myResult" | ||
| + | } | ||
| + | read file to parameter | ||
| + | # read file to parameter | ||
| + | # $1 Filepath | ||
| + | # $2 Logfiledestination | ||
| + | ReadFile() | ||
| + | { | ||
| + | local myResult='' | ||
| + | WriteLog 'ReadFile '$1 $2 | ||
| + | if [ -e $1 ]; then | ||
| + | myResult=$(cat $1 | grep -v '#' |\ | ||
| + | while read myResult; | ||
| + | do | ||
| + | echo $myResult | ||
| + | done | ||
| + | ) | ||
| + | else | ||
| + | WriteLog 'ReadFile Error File '$1 $2 | ||
| + | exit 1 | ||
| + | fi | ||
| + | echo "$myResult" | ||
| + | } | ||
Version vom 25. August 2014, 06:56 Uhr
Funktion
- get script path
# get script path
GetScriptPath()
{
echo "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
}
- write logfile
# write logfile
# $1 Description
# $2 Logfiledestination
WriteLog ()
{
echo $(date "+%y%m%d-%H%M%S")' '$1 >> $2
}
- change from upper to lower char
# change from upper to lower char
# $1 Variable to change
# $2 Logfiledestionation
LowerChar ()
{
WriteLog 'LowerChar '$1 $2
local myResult=`echo $1 | tr 'A-Z' 'a-z'`
echo "$myResult"
}
read file to parameter
# read file to parameter
# $1 Filepath
# $2 Logfiledestination
ReadFile()
{
local myResult=
WriteLog 'ReadFile '$1 $2
if [ -e $1 ]; then
myResult=$(cat $1 | grep -v '#' |\
while read myResult;
do
echo $myResult
done
)
else
WriteLog 'ReadFile Error File '$1 $2
exit 1
fi
echo "$myResult"
}