bash:tests:exit_if_file_is_not_there
Differences
This shows you the differences between two versions of the page.
bash:tests:exit_if_file_is_not_there [2023/06/13 21:16] – created peter | bash: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: | + | **NOTE: |
- | + | ||
- | * Actually just using **exit** should be enough, as it returns the status value of previous command (exit equals to exit $?). | + | |
</ | </ | ||
---- | ---- | ||
+ | |||
+ | ===== Exit if path does not exist ===== | ||
<code bash> | <code bash> | ||
cd /some/path || exit 1 | cd /some/path || exit 1 | ||
</ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | </ | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
Line 25: | Line 34: | ||
</ | </ | ||
- | This will ensure that script | + | <WRAP info> |
+ | **NOTE: | ||
+ | |||
+ | * Usually this command should not be set in a command-line shell, but in a script | ||
+ | |||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== 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: | ||
</ | </ | ||
- | Note that -e would be any file/ | + | <WRAP info> |
+ | **NOTE: | ||
+ | </ | ||
<code bash> | <code bash> |
bash/tests/exit_if_file_is_not_there.1686690992.txt.gz · Last modified: 2023/06/13 21:16 by peter