Seite 2 von 2 ErsteErste 12
Ergebnis 11 bis 11 von 11
  1. #11
    Pike_Bishop
    Gast
    Hi Lucifer,

    i think i'am not the best teacher but i will try to explain it;

    programs in linux are returns an exit status and if all is ok this exit status is 0 (zero)
    if the program fails then the exit status is nonzero as example 1 or whatever.

    to try, write only the command mv in telnet and press the enter button, then you can see following;
    Code:
    BusyBox v1.24.1 (2017-03-16 11:12:22 CET) multi-call binary.
    
    Usage: mv [-fin] SOURCE DEST
    or: mv [-fin] SOURCE... DIRECTORY
    
    Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY
    
            -f      Don't prompt before overwriting
            -i      Interactive, prompt before overwrite
            -n      Don't overwrite an existing file
    ok, and now make echo $? in telnet then you got the following output;
    Code:
    1
    this is the exit status from the command mv which is failed in this case because mv need options too.
    and now make echo "take it" in telnet and as next again echo $?;
    if the command was successful you got now the output;
    Code:
    0
    now you know the command echo "take it" was successful since the exit status is zero.

    so a simple way to check exit status with telnet as you can see is the command echo $?

    in scripts i personally use only exit if a script is successful or exit 1 if a command in the script fails.
    you can check the exit status in scripts as following also;
    Code:
            if [ "$?" = "0" ] ; then
                echo "blablabla"
            else
                  echo "failed" && exit 1
            fi
    as example (from my dvdcopy script);
    Code:
    if [ ! -f $DVDBACKUP ] ; then
        opkg install $DVDBACKUP_PACKAGE
        
            if [ "$?" = "0" ] ; then
                echo -e "Installation Programm $DVDBACKUP_PACKAGE erfolgreich\n"
            else
                echo "ABBRUCH ! Installation Programm $DVDBACKUP_PACKAGE fehlgeschlagen !"
                echo "Eventuell weil die Paketmanagement Aktualisierung zuvor fehlschlug"
                echo -e "Bitte Programm $DVDBACKUP_PACKAGE manuell installieren, und das Script erneut starten\n" && exit 1
            fi
            
    else
        echo -e "Programm $DVDBACKUP_PACKAGE ist vorhanden\n"
    fi
    if the command to install $DVDBACKUP_PACKAGE fails so you can see at the else branch under if [ "$?" = "0" ] ; then i use exit 1
    you do not have to use exit 1 if the script (command) fails at this part, the script ends also if you use exit or exit 0 or exit 1 but in this case exit 1 is correct.

    and at last here a link to the exit status;
    Exit Codes With Special Meanings


    regards
    Pike
    Geändert von Pike_Bishop (10.06.2017 um 20:29 Uhr)

  2. Thanks Lucifer bedankten sich
    •   Alt Advertising

       


Seite 2 von 2 ErsteErste 12

Stichworte

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •  
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:24 Uhr.
Powered by vBulletin® Version 4.2.5 (Deutsch)
Copyright ©2024 Adduco Digital e.K. und vBulletin Solutions, Inc. Alle Rechte vorbehalten.
Resources saved on this page: MySQL 5,56%
Parts of this site powered by vBulletin Mods & Addons from DragonByte Technologies Ltd. (Details)
vBulletin Skin By: PurevB.com