23 Mart 2022 Çarşamba

command komutu

Giriş
Açıklaması şöyle
... you can use command -v to check for availability of a command. No need to check its output, command will tell you via its exit status if it succeeded to find the command or not (regardless of whether it's an external command found in $PATH, a builtin or a function)

command is a mandatory POSIX utility. The -v option to command used to be optional, but it's not any longer in the latest version of the POSIX specification
Örnek
Şöyle yaparız. "#!/usr/bin/sh -" kullanımının açıklaması burada
#!/usr/bin/sh -

main() {
    for mycommand do
        printf >&2 '%s\n' "Checking $mycommand"
        if ! command -v -- "$mycommand" > /dev/null 2>&1; then
            printf >&2 '%s\n' "I think I am missing $mycommand"
        fi
    done
}

main less asdf


Hiç yorum yok:

Yorum Gönder