{"id":21208,"date":"2025-11-09T11:17:45","date_gmt":"2025-11-09T10:17:45","guid":{"rendered":"https:\/\/linux-bibel.at\/?p=21208"},"modified":"2025-11-09T11:18:22","modified_gmt":"2025-11-09T10:18:22","slug":"die-shell-und-der-returncode","status":"publish","type":"post","link":"https:\/\/linux-bibel.at\/index.php\/2025\/11\/09\/die-shell-und-der-returncode\/","title":{"rendered":"Die shell und der Returncode"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Jedes Linux\/Unix Standard-Kommando gibt nach der Ausf\u00fchrung einen Status zur\u00fcck. Wobei der Status 0 f\u00fcr OK bzw &#8222;true&#8220; steht. Ein anderer Status deutet auf ein Problem hin<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wie kann ich diesen Abfragen. <\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><br>De Shell kennt Variable, diese werden mit einem $ und dem Namen abgefragt. Eine Konvention ist, dass sie gro\u00df geschrieben werden sollen. Anzeigen kann man diese mit dem Befehl &#8222;echo  $VARIABLE-NAME&#8220;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">eine Eingabe von <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo $USER<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">gibt den Namen zur\u00fcck mit dem man eingeloggt ist. <br>Zur\u00fcck zu unserem ReturnCode, der in der Variable $? abgespeichert wird.  Und bei JEDEM Befehl neu \u00fcberschrieben wird !!!!!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Die Befehle <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls\necho $?\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><br>Der echo zeigt dir den letzten Returncode an. Also den. des ls Befehl. So kann ich in einem script \u00fcberpr\u00fcfen ob, der Befehl ordnungsgem\u00e4\u00df abgelaufen ist.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verkettung von Befehlen<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Ihr kennt ja sicher schon das | Zeichen. Womit ich die Ausgabe des 1. Befehls an den 2. weitergegeben wird. Ein typische Vertreter w\u00e4re<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nls -lasiR | more<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><br>Die endlos lange Ausgabe erfolgt jetzt seitenweise. <br>Seid ihr aber schon \u00fcber &amp;&amp; und || gestolpert?<br><br>Damit verkette ich mehrere Befehle, die nur dann ausgef\u00fchrt werden, wenn der vorher gehende ordnungsgem\u00e4\u00df beendet wurde (&amp;&amp;). Oder wenn ein Fehler vorliegt. (||).<br> <br>Ein Beispiel: <br><br>tar czf \/media\/sicherung\/sicher-heute.tgz \/home &amp;&amp; umount \/meine\/sicherung &amp;&amp; shutdown now<br><br>Diese Befehlskette w\u00fcrde das \/home Verzeichnis auf eine Platte die unter \/media\/sicherung gemountet ist, in die Datei sicher-heute.tgz speichern. Wenn dies ohne Fehler durchl\u00e4uft erfolgt ein umount der Platte und das System wird heruntergefahren. <br>Tritt ein Problem auf, wird die Kette unterbrochen und das System l\u00e4uft weiter. <br>tar czf \/media\/sicherung\/sicher-heute.tgz \/home &amp;&amp; echo &#8222;Alles in Ordnung&#8220; || echo &#8222;Fehler Nummer $?&#8220;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Das w\u00e4re ein Beispiel, wo eine Meldung bei Ok und eine andere wenn etwas schief geht ausgegeben wird. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Welche Fehlernummern gibt es?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Nun jetzt wird es schwierig. Es gibt kein standardisiertes Fehlerverzeichnis Jedes Programm darf seine eigenen Codes zur\u00fcckgeben. Da Programmierer faule Leute sind, haben sich die meisten an die C-Standards gehalten. die ich euch dazugebe. Aber Garantie ist das keine. <br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">C-Fehlercodes (ohne Gew\u00e4hr)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1\tEPERM\tOperation not permitted<br>2\tENOENT\tNo such file or directory<br>3\tESRCH\tNo such process<br>4\tEINTR\tInterrupted system call<br>5\tEIO\tI\/O error<br>6\tENXIO\tNo such device or address<br>7\tE2BIG\tArgument list too long<br>8\tENOEXEC\tExec format error<br>9\tEBADF\tBad file number<br>10\tECHILD\tNo child processes<br>11\tEAGAIN\tTry again<br>12\tENOMEM\tOut of memory<br>13\tEACCES\tPermission denied<br>14\tEFAULT\tBad address<br>15\tENOTBLK\tBlock device required<br>16\tEBUSY\tDevice or resource busy<br>17\tEEXIST\tFile exists<br>18\tEXDEV\tCross-device link<br>19\tENODEV\tNo such device<br>20\tENOTDIR\tNot a directory<br>21\tEISDIR\tIs a directory<br>22\tEINVAL\tInvalid argument<br>23\tENFILE\tFile table overflow<br>24\tEMFILE\tToo many open files<br>25\tENOTTY\tNot a typewriter<br>26\tETXTBSY\tText file busy<br>27\tEFBIG\tFile too large<br>28\tENOSPC\tNo space left on device<br>29\tESPIPE\tIllegal seek<br>30\tEROFS\tRead-only file system<br>31\tEMLINK\tToo many links<br>32\tEPIPE\tBroken pipe<br>33\tEDOM\tMath argument out of domain of func<br>34\tERANGE\tMath result not representable<br>35\tEDEADLK\tResource deadlock would occur<br>36\tENAMETOOLONG\tFile name too long<br>37\tENOLCK\tNo record locks available<br>38\tENOSYS\tFunction not implemented<br>39\tENOTEMPTY\tDirectory not empty<br>40\tELOOP\tToo many symbolic links encountered<br>42\tENOMSG\tNo message of desired type<br>43\tEIDRM\tIdentifier removed<br>44\tECHRNG\tChannel number out of range<br>45\tEL2NSYNC\tLevel 2 not synchronized<br>46\tEL3HLT\tLevel 3 halted<br>47\tEL3RST\tLevel 3 reset<br>48\tELNRNG\tLink number out of range<br>49\tEUNATCH\tProtocol driver not attached<br>50\tENOCSI\tNo CSI structure available<br>51\tEL2HLT\tLevel 2 halted<br>52\tEBADE\tInvalid exchange<br>53\tEBADR\tInvalid request descriptor<br>54\tEXFULL\tExchange full<br>55\tENOANO\tNo anode<br>56\tEBADRQC\tInvalid request code<br>57\tEBADSLT\tInvalid slot<br>59\tEBFONT\tBad font file format<br>60\tENOSTR\tDevice not a stream<br>61\tENODATA\tNo data available<br>62\tETIME\tTimer expired<br>63\tENOSR\tOut of streams resources<br>64\tENONET\tMachine is not on the network<br>65\tENOPKG\tPackage not installed<br>66\tEREMOTE\tObject is remote<br>67\tENOLINK\tLink has been severed<br>68\tEADV\tAdvertise error<br>69\tESRMNT\tSrmount error<br>70\tECOMM\tCommunication error on send<br>71\tEPROTO\tProtocol error<br>72\tEMULTIHOP\tMultihop attempted<br>73\tEDOTDOT\tRFS specific error<br>74\tEBADMSG\tNot a data message<br>75\tEOVERFLOW\tValue too large for defined data type<br>76\tENOTUNIQ\tName not unique on network<br>77\tEBADFD\tFile descriptor in bad state<br>78\tEREMCHG\tRemote address changed<br>79\tELIBACC\tCan not access a needed shared library<br>80\tELIBBAD\tAccessing a corrupted shared library<br>81\tELIBSCN\t.lib section in a.out corrupted<br>82\tELIBMAX\tAttempting to link in too many shared libraries<br>83\tELIBEXEC\tCannot exec a shared library directly<br>84\tEILSEQ\tIllegal byte sequence<br>85\tERESTART\tInterrupted system call should be restarted<br>86\tESTRPIPE\tStreams pipe error<br>87\tEUSERS\tToo many users<br>88\tENOTSOCK\tSocket operation on non-socket<br>89\tEDESTADDRREQ\tDestination address required<br>90\tEMSGSIZE\tMessage too long<br>91\tEPROTOTYPE\tProtocol wrong type for socket<br>92\tENOPROTOOPT\tProtocol not available<br>93\tEPROTONOSUPPORT\tProtocol not supported<br>94\tESOCKTNOSUPPORT\tSocket type not supported<br>95\tEOPNOTSUPP\tOperation not supported on transport endpoint<br>96\tEPFNOSUPPORT\tProtocol family not supported<br>97\tEAFNOSUPPORT\tAddress family not supported by protocol<br>98\tEADDRINUSE\tAddress already in use<br>99\tEADDRNOTAVAIL\tCannot assign requested address<br>100\tENETDOWN\tNetwork is down<br>101\tENETUNREACH\tNetwork is unreachable<br>102\tENETRESET\tNetwork dropped connection because of reset<br>103\tECONNABORTED\tSoftware caused connection abort<br>104\tECONNRESET\tConnection reset by peer<br>105\tENOBUFS\tNo buffer space available<br>106\tEISCONN\tTransport endpoint is already connected<br>107\tENOTCONN\tTransport endpoint is not connected<br>108\tESHUTDOWN\tCannot send after transport endpoint shutdown<br>109\tETOOMANYREFS\tToo many references: cannot splice<br>110\tETIMEDOUT\tConnection timed out<br>111\tECONNREFUSED\tConnection refused<br>112\tEHOSTDOWN\tHost is down<br>113\tEHOSTUNREACH\tNo route to host<br>114\tEALREADY\tOperation already in progress<br>115\tEINPROGRESS\tOperation now in progress<br>116\tESTALE\tStale NFS file handle<br>117\tEUCLEAN\tStructure needs cleaning<br>118\tENOTNAM\tNot a XENIX named type file<br>119\tENAVAIL\tNo XENIX semaphores available<br>120\tEISNAM\tIs a named type file<br>121\tEREMOTEIO\tRemote I\/O error<br>122\tEDQUOT\tQuota exceeded<br>123\tENOMEDIUM\tNo medium found<br>124\tEMEDIUMTYPE\tWrong medium type<br>125\tECANCELED\tOperation Canceled<br>126\tENOKEY\tRequired key not available<br>127\tEKEYEXPIRED\tKey has expired<br>128\tEKEYREVOKED\tKey has been revoked<br>129\tEKEYREJECTED\tKey was rejected by service<br>130\tEOWNERDEAD\tOwner died<br>131\tENOTRECOVERABLE\tState not recoverable<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Klassifizierung<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ungef\u00e4hrlich<\/li>\n\n\n\n<li>Die Beispiele sind mit der notwendigen Vorsicht auszuf\u00fchren. Sie k\u00f6nnen ein Filesystem voll machen.<\/li>\n\n\n\n<li>Minimale Programmier-\/Scriptkenntnisse bzw. EDV-Verst\u00e4ndnis sollte vorhanden <\/li>\n<\/ul>\n<div class=\"pld-like-dislike-wrap pld-custom\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"Gef\u00e4llt mir\" data-post-id=\"21208\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                            <img src=\"https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/12\/Daumen-Hoch.png\" alt=\"Gef\u00e4llt mir\" \/>\r\n            <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">6    <\/span>\r\n<\/div><div class=\"pld-dislike-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-dislike-trigger pld-like-dislike-trigger  \" title=\"Gef\u00e4llt mir nicht\" data-post-id=\"21208\" data-trigger-type=\"dislike\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                            <img src=\"https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/12\/Daumen-Runter.png\" alt=\"Gef\u00e4llt mir nicht\" \/>\r\n            <\/a>\r\n    <span class=\"pld-dislike-count-wrap pld-count-wrap\"><\/span>\r\n<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Jedes Linux\/Unix Standard-Kommando gibt nach der Ausf\u00fchrung einen Status zur\u00fcck. Wobei der Status 0 f\u00fcr OK bzw &#8222;true&#8220; steht. Ein anderer Status deutet auf ein Problem hin Wie kann ich diesen Abfragen. De Shell kennt Variable, diese werden mit einem $ und dem Namen abgefragt. Eine Konvention ist, dass sie gro\u00df geschrieben werden sollen. Anzeigen [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":21218,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,61,17],"tags":[1439,1435],"class_list":["post-21208","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-allgemein","category-scripts","category-system","tag-die-beispiele-sind-mit-der-notwendigen-vorsicht-auszufuehren","tag-ungefaehrlich"],"_links":{"self":[{"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/posts\/21208","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/comments?post=21208"}],"version-history":[{"count":4,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/posts\/21208\/revisions"}],"predecessor-version":[{"id":21219,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/posts\/21208\/revisions\/21219"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/media\/21218"}],"wp:attachment":[{"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/media?parent=21208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/categories?post=21208"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/tags?post=21208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}