Difference between revisions of "$?"

From wikieduonline
Jump to navigation Jump to search
 
(13 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[echo]] $?
+
<code>[[echo $?]]</code> prints the [[exit status]] of the last executed command in the terminal. The exit status is a numeric value that indicates whether the command completed successfully or encountered an error. A value of [[0]] indicates success, while non-zero values indicate an [[error]].
  
  mkdir -p /path/to/root/in/macos
+
== Examples ==
 +
  [[mkdir -p]] /path/to/root/in/macos
 
  mkdir: cannot create directory ‘/path’: [[Read-only file system]]
 
  mkdir: cannot create directory ‘/path’: [[Read-only file system]]
 +
 +
-p, --parents makes parents directories if needed and no error if existing
 
   
 
   
 
  echo $?
 
  echo $?
 
  1
 
  1
 +
 +
[[apt -qqq update -y && apt -qqq upgrade -y; echo $?]]
  
 
== Related ==
 
== Related ==
 
* <code>[[exit]]</code>
 
* <code>[[exit]]</code>
 +
* <code>[[$]]</code>
 +
* <code>[[apt update]]</code>
  
 
== See also ==
 
== See also ==
 +
* {{exit}}
 
* {{set}}
 
* {{set}}
 
* {{Bash}}
 
* {{Bash}}
  
 
[[Category:Bash]]
 
[[Category:Bash]]

Latest revision as of 06:54, 7 June 2024

echo $? prints the exit status of the last executed command in the terminal. The exit status is a numeric value that indicates whether the command completed successfully or encountered an error. A value of 0 indicates success, while non-zero values indicate an error.

Examples[edit]

mkdir -p /path/to/root/in/macos
mkdir: cannot create directory ‘/path’: Read-only file system
-p, --parents makes parents directories if needed and no error if existing

echo $?
1
apt -qqq update -y && apt -qqq upgrade -y; echo $?

Related[edit]

See also[edit]

Advertising: