Diese Stack Overflow-Antwort von Nicolas Martyanoff bietet eine vollständige Lösung. Ich habe es optimiert, um die in den Kommentaren erwähnte neuere Syntax zu verwenden.
Ermitteln Sie das Betriebssystem:
platform='unknown'
unamestr=$(uname)
if [ "$unamestr" = 'Linux' ]; then
platform='linux'
elif [ "$unamestr" = 'FreeBSD' ]; then
platform='freebsd'
fi
Wählen Sie die richtigen Flaggen für ls
:
if [ "$platform" = 'linux' ]; then
alias ls='ls --color=auto'
elif [ "$platform" = 'freebsd' ]; then
alias ls='ls -G'
fi