User Tools

Site Tools


bash:tests:exit_if_file_is_not_there

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

bash:tests:exit_if_file_is_not_there [2023/06/13 21:16] – created peterbash:tests:exit_if_file_is_not_there [2023/06/13 21:26] (current) peter
Line 1: Line 1:
 ====== BASH - Tests - Exit if file is not there ====== ====== BASH - Tests - Exit if file is not there ======
 +
 +===== Exit if file is not there =====
  
 <code bash> <code bash>
Line 6: Line 8:
  
 <WRAP info> <WRAP info>
-**NOTE:**  Will exit if file is not there, same thing should be used if you use cd in your scripts +**NOTE:**  Just using **exit** should be enough, as it returns the status value of previous command (exit equals to exit $?).
- +
-  * Actually just using **exit** should be enough, as it returns the status value of previous command (exit equals to exit $?). +
 </WRAP> </WRAP>
  
 ---- ----
 +
 +===== Exit if path does not exist =====
  
 <code bash> <code bash>
 cd /some/path || exit 1 cd /some/path || exit 1
 </code> </code>
 +
 +<WRAP info>
 +**NOTE:**  Will exit if path does not exist.
 +</WRAP>
 +
 +
 +----
 +
  
  
Line 25: Line 34:
 </code> </code>
  
-This will ensure that script doesn’t continue if dir doesn’t exist. Another way might be:+<WRAP info> 
 +**NOTE:**  The **set -e** option instructs bash to immediately exit if any command has a non-zero exit status. 
 + 
 +  * Usually this command should not be set in a command-line shell, but in a script it is massively helpful. 
 + 
 +</WRAP> 
 + 
 +---- 
 + 
 +===== Do not continue if the directory does not exist =====
  
 <code bash> <code bash>
Line 34: Line 52:
 ---- ----
  
-Do something if directory is there+===== Do something if directory is there =====
  
 <code bash> <code bash>
Line 51: Line 69:
 </code> </code>
  
-Note that -e would be any file/dir/socket/node, -d is dir and so on+<WRAP info> 
 +**NOTE:**  **-e** would be any file/dir/socket/node, **-d** is directory, and so on
 +</WRAP> 
  
 <code bash> <code bash>
bash/tests/exit_if_file_is_not_there.1686690992.txt.gz · Last modified: 2023/06/13 21:16 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki