Bash / shell
Articles in the Bash / shell category (15).
Articles in the Bash / shell category (15).
- Bash arrays: syntax reference — Create, read, modify and loop over indexed arrays in Bash, with a reference of the common syntax.
- Bash for loops and the find -exec alternative — Practical shell one-liners (killing processes, lsof) plus a refresher on for loops, ranges, tcsh foreach and find -exec.
- Bash parameter expansion: indirect variables, substitution and sed — Use Bash indirect expansion ${!name}, pattern substitution ${var//pattern/...}, sed for case changes and command substitution.
- Bash script to run an Oracle SQL query — Shell script that checks the Oracle environment and runs a typed query with sqlplus -s.
- Bash special parameters: $?, $0, $#, $$ — Quick reference to the Bash special parameters for the exit status, script name, argument count and shell process ID.
- Bash: get the directory and file name from a path — Use dirname and basename to split a path in a shell script.
- Bash: if conditions, test operators and case — Bash conditions cheat sheet: if/elif/else, integer, string and file operators, case, boolean operators and using a function as a condition.
- Bash: read a command's exit status with $? — Use $? to get the exit status of the last command.
- Customizing ls colors with LS_COLORS — Change the LS_COLORS variable to alter ls colors in bash: SGR codes, file type keys and a terminal color preview.
- Extract the file name, extension and directory in Bash — Split a path into directory, file name and extension with basename, dirname and Bash parameter expansion.
- Long shell commands with sudo sh -c: quoting — Two patterns to run a long shell command with pipes and quotes as root, and the escaping pitfalls to avoid.
- Run a Bash script on remote servers over SSH — Check memory, CPU, TCP connections and kernel on a list of Linux servers using ssh and bash -s.
- Shell: count lines per file in a directory — Bash script that prints the line count of each file in a directory with a running total, and its limits with complex file names.
- Shell: current date in a custom format — Get the current date and time into a bash variable with printf (bash 4.2 and later) or with the date command (older versions).
- Shell: empty or truncate a file — Shell commands to empty an existing file (truncate, redirection) or replace it with an empty file, and how they differ.