2022-06-25 11:42:21 +02:00
|
|
|
---
|
|
|
|
title: Bash
|
2022-11-19 15:25:20 +01:00
|
|
|
visible: true
|
2022-06-25 11:42:21 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
[toc]
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-06-25 11:42:21 +02:00
|
|
|
## Returning exit status
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-06-25 11:42:21 +02:00
|
|
|
`exit 1`
|
|
|
|
|
2023-02-23 14:48:51 +01:00
|
|
|
| Code | Meaning |
|
|
|
|
| ---- | ------- |
|
|
|
|
| 0 | Success |
|
|
|
|
| 1 | Error |
|
2022-06-25 11:42:21 +02:00
|
|
|
|
|
|
|
## Check for Arguments given
|
2023-02-23 14:48:51 +01:00
|
|
|
|
|
|
|
```sh
|
2022-06-25 11:42:21 +02:00
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
echo "Please supply one argument"
|
|
|
|
$(exit 1); echo "$?"
|
|
|
|
elif [ $# -ge 2 ]; then
|
|
|
|
echo "Please give only one argument"
|
|
|
|
$(exit 1); echo "$?"
|
|
|
|
fi
|
|
|
|
```
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-06-25 11:42:21 +02:00
|
|
|
## Multiline output
|
2023-02-23 14:48:51 +01:00
|
|
|
|
|
|
|
```sh
|
2022-06-25 11:42:21 +02:00
|
|
|
cat << EOF
|
|
|
|
Line 1
|
|
|
|
Line 2
|
|
|
|
Line 3
|
|
|
|
EOF
|
|
|
|
```
|
2023-02-23 14:48:51 +01:00
|
|
|
|
|
|
|
Will output:
|
|
|
|
|
2022-06-25 11:42:21 +02:00
|
|
|
```
|
|
|
|
Line 1
|
|
|
|
Line 2
|
|
|
|
Line 3
|
2022-11-19 15:25:20 +01:00
|
|
|
```
|