Make add-shell correctly handle /etc/shells files that do not end with newlines

Fixes https://github.com/fish-shell/fish-shell/issues/77
This commit is contained in:
ridiculousfish 2012-07-22 16:59:08 -07:00
parent 261bf12c91
commit 56599621cc

View File

@ -21,7 +21,7 @@ tmpfile=${file}.tmp
set -o noclobber set -o noclobber
trap "rm -f $tmpfile" EXIT trap "rm -f $tmpfile" EXIT
if ! cat $file > $tmpfile if ! cat $file > $tmpfile
then then
cat 1>&2 <<EOF cat 1>&2 <<EOF
@ -31,11 +31,16 @@ EOF
exit 1 exit 1
fi fi
# Append a newline if it doesn't exist
if [ "$(tail -c1 "$tmpfile"; echo x)" != $'\nx' ]; then
echo "" >> "$tmpfile"
fi
for i for i
do do
if ! grep -q "^${i}$" $tmpfile if ! grep -q "^${i}$" "$tmpfile"
then then
echo $i >> $tmpfile echo $i >> "$tmpfile"
fi fi
done done