Hands-on Lab·Red Hat Certified System Administrator
Running Shell Scripts
Not an objective on its own, and assumed by all four that are. Three things stop a new script running and all three are demonstrated: no execute bit, the current directory not being on PATH, and the shebang.
Shell Scripts Guide 61 of 67 Beginner
- OSRHEL 10.0
- Kernel6.12.0-55.9.1.el10_0
- dnf4.20.0
- Flatpak1.16.0
- TimeAbout 9 min
#!/usr/bin/bash and #!/bin/bash both work on RHEL - /bin is a symlink to /usr/bin. #!/bin/sh is a *different* request: it asks for POSIX shell behaviour, and bashisms like [[ ]] may not work under it.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| RHCSA-A01 | 192.168.0.31 | RHEL 10.0 | Practice node (graded) - spare /dev/sda | 2 Core | 4 GB | 50 GB + 15 GB |
This guide includes
Use this before the four scripting objectives, every one of which assumes it. This matters because a script fails three different ways before it ever reaches your code - and each of the three has a different fix.
- meeting the three ways a script fails to run, and the fix for each
- writing a shebang, and finding what it actually points at
- finding that the interpreter named there is itself a symlink
Before you start
- A shell.
- The session writes and removes
~/scripts.
-
Three ways it fails, and three fixes
-
The shebang