mirror of
https://github.com/MinecraftServerControl/mscs.git
synced 2024-11-15 14:58:18 -07:00
Modify {get|set}Value to work with Windows formatted files
This commit is contained in:
parent
cd532d146c
commit
93dbb42ce3
20
msctl
20
msctl
@ -608,8 +608,14 @@ getValue() {
|
||||
# Make sure the file exists.
|
||||
if [ -e "$1" ]; then
|
||||
# Find the key/value combo.
|
||||
KEY=$($PERL -ne 'if ($_ =~ /^('$2')=.*$/i) { print lc $1; }' $1)
|
||||
VALUE=$($PERL -ne 'if ($_ =~ /^'$2'=(.*)$/i) { print $1; }' $1)
|
||||
KEY=$($PERL -ne '
|
||||
$_ =~ s/[\r]//;
|
||||
if ($_ =~ /^('$2')=.*$/i) { print lc $1; }
|
||||
' $1)
|
||||
VALUE=$($PERL -ne '
|
||||
$_ =~ s/[\r]//;
|
||||
if ($_ =~ /^'$2'=(.*)$/i) { print $1; }
|
||||
' $1)
|
||||
fi
|
||||
# Return the value if found, the default value if not.
|
||||
if [ -n "$KEY" ] && [ -n "$VALUE" ]; then
|
||||
@ -632,9 +638,15 @@ setValue() {
|
||||
touch "$1"
|
||||
# Replace the key/value combo if it already exists, otherwise just
|
||||
# append it to the end of the file.
|
||||
KEY_VALUE=$($PERL -ne 'if ($_ =~ /^('$2'=.*)$/) { print "$1"; }' $1)
|
||||
KEY_VALUE=$($PERL -ne '
|
||||
$_ =~ s/[\r]//;
|
||||
if ($_ =~ /^('$2'=.*)$/) { print "$1"; }
|
||||
' $1)
|
||||
if [ -n "$KEY_VALUE" ]; then
|
||||
$PERL -i -ne "if (\$_ =~ /^$2=.*$/) { print \"$2=$3\\n\"; } else { print; }" "$1"
|
||||
$PERL -i -ne '
|
||||
$_ =~ s/[\r]//;
|
||||
if ($_ =~ /^'$2'=.*$/) { print "'$2'='$3'\n"; } else { print; }
|
||||
' $1
|
||||
else
|
||||
printf "$2=$3\n" >> "$1"
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user