linux-assistant
linux-assistant copied to clipboard
Use alternatives to check if a command exists
Hi Jean-Frédéric,
ich habe deinen Vortrag auf dem CLT24 gesehen und habe mir gedacht, dass es dich interessieren könnte, dass man statt wie in https://github.com/Jean28518/linux-assistant/blob/63940cf56e3604655937f91ecc4bb59519280b46/lib/services/linux.dart#L2557 auch anders, eventuell effizienter herausbekommen kann, ob "$firstWord" ein Befehl ist:
$ type -a zypper
zypper is aliased to `/usr/bin/sudo zypper'
zypper is /usr/bin/zypper
$ type -a züpper
-bash: type: züpper: not found
$ which zypper
/usr/bin/zypper
$ which züpper
which: no züpper in (/home/thomas/bin:/home/thomas/.local/bin:/home/thomas/bin:/usr/local/bin:/usr/bin:/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin:/home/thomas/go/bin)
$ hash zypper ; echo $?
0
$ hash züpper ; echo $?
-bash: hash: züpper: not found
1
Ansonsten finde ich deinen Linux-Assistant MEGA!!!! (zumindest für Leute, die mit Linux eher am Anfang stehen - ich bin seit 1992 damit in Kontakt und brauche es daher "leider" nicht mehr 😁 )
Danke für Deinen Tipp, werde ich umstetzen!