{"id":18427,"date":"2024-05-08T13:53:18","date_gmt":"2024-05-08T20:53:18","guid":{"rendered":"https:\/\/ioflood.com\/blog\/?p=18427"},"modified":"2024-05-15T15:31:17","modified_gmt":"2024-05-15T22:31:17","slug":"bash-syntax-cheat-sheet","status":"publish","type":"post","link":"https:\/\/ioflood.com\/blog\/bash-syntax-cheat-sheet\/","title":{"rendered":"Bash Syntax Cheat Sheet"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"alignright size-full is-resized\"><img decoding=\"async\" src=\"https:\/\/ioflood.com\/blog\/wp-content\/uploads\/2024\/03\/Artistic-digital-illustration-of-Bash-Syntax-Cheat-Sheet-focusing-on-essential-Bash-syntax-and-commands-300x300.jpg\" alt=\"Artistic digital illustration of Bash Syntax Cheat Sheet focusing on essential Bash syntax and commands\" width=\"300\" height=\"300\" title=\"\"><\/figure>\n<\/div>\n<p>Managing <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/phoenix-dedicated-servers.php\">dedicated servers<\/a> and performing system administration tasks at <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/\">IOFLOOD<\/a> requires a solid understanding of Bash syntax to efficiently automate processes and troubleshoot issues. Drawing from our experience in server management and software deployment, we&#8217;ve compiled this comprehensive Bash reference guide.<\/p>\n<p>This <strong>Bash Cheat Sheet<\/strong> is your concise companion in the vast world of Bash programming. With a <strong>dedicated reference section for commands and key programming concepts, followed by practical example code snippets<\/strong>, this cheat sheet is designed to assist both beginners and seasoned professionals alike.<\/p>\n<p>So, let&#8217;s set sail on this exciting journey to unlock the full potential of Bash. Ready your terminals, and let\u2019s dive into Bash!<\/p>\n<h2>Command Reference Section<\/h2>\n<p>Before diving into practical examples, let&#8217;s explore the various commands and concepts of Bash. <strong>This reference section will also provide explanations and example usage cases<\/strong> when applicable. These topics will serve as key tools while scripting in Bash and will also deepen your understanding of the following Sample Code.<\/p>\n<h2>Command Chaining<\/h2>\n<table>\n<thead>\n<tr>\n<th>Command\/Concept<\/th>\n<th>Description<\/th>\n<th>Syntax Example<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>&amp;&amp;<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-and-operator\/\">Executes a secondary command<\/a> only if the first command succeeds.<\/td>\n<td><code>command1 &amp;&amp; command2<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>||<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-if-or\/\">Or Operator<\/a> executes secondary command only if the first command fails.<\/td>\n<td><code>command1 || command2<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>;<\/code><\/td>\n<td>Executes all commands in sequence, regardless of their exit status.<\/td>\n<td><code>command1; command2<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>|<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-pipe\/\">Pipes the output<\/a> of the first command to the input of the second command.<\/td>\n<td><code>command1 \\| command2<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>&amp;<\/code><\/td>\n<td>Runs the command in the background, allowing the terminal to accept new commands immediately.<\/td>\n<td><code>command1 &amp;<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Common Commands<\/h2>\n<table>\n<thead>\n<tr>\n<th>Command<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>ls<\/code><\/td>\n<td>Lists the contents of a directory.<\/td>\n<td><code>ls -l<\/code> lists in long format.<\/td>\n<\/tr>\n<tr>\n<td><code>cd<\/code><\/td>\n<td>Changes the current directory.<\/td>\n<td><code>cd \/home<\/code> changes to the \/home directory.<\/td>\n<\/tr>\n<tr>\n<td><code>pwd<\/code><\/td>\n<td>Prints the <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/pwd-linux-command\/\">current working directory<\/a>.<\/td>\n<td><code>pwd<\/code> displays the current directory path.<\/td>\n<\/tr>\n<tr>\n<td><code>mkdir<\/code><\/td>\n<td>Creates a <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/mkdir-linux-command\/\">new directory<\/a>.<\/td>\n<td><code>mkdir new_dir<\/code> creates a new directory named <code>new_dir<\/code>.<\/td>\n<\/tr>\n<tr>\n<td><code>rm<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/rm-linux-command\/\">Removes files or directories<\/a>.<\/td>\n<td><code>rm file.txt<\/code> removes <code>file.txt<\/code>. Use <code>-r<\/code> for directories.<\/td>\n<\/tr>\n<tr>\n<td><code>echo<\/code><\/td>\n<td>Displays a line of text.<\/td>\n<td><code>echo \"Hello World\"<\/code> prints Hello World.<\/td>\n<\/tr>\n<tr>\n<td><code>cat<\/code><\/td>\n<td>Concatenates and displays files.<\/td>\n<td><code>cat file.txt<\/code> displays the contents of <code>file.txt<\/code>.<\/td>\n<\/tr>\n<tr>\n<td><code>touch<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/touch-linux-command\/\">Creates an empty file<\/a> or updates the timestamp.<\/td>\n<td><code>touch new_file.txt<\/code> creates or updates <code>new_file.txt<\/code>.<\/td>\n<\/tr>\n<tr>\n<td><code>cp<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/cp-linux-command\/\">Copies files and directories<\/a>.<\/td>\n<td><code>cp source.txt dest.txt<\/code> copies <code>source.txt<\/code> to <code>dest.txt<\/code>.<\/td>\n<\/tr>\n<tr>\n<td><code>mv<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/mv-linux-command\/\">Moves or renames files<\/a> and directories.<\/td>\n<td><code>mv old_name.txt new_name.txt<\/code> renames\/moves a file.<\/td>\n<\/tr>\n<tr>\n<td><code>grep<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/grep-linux-command\/\">Searches for patterns<\/a> in files.<\/td>\n<td><code>grep \"search_term\" file.txt<\/code> searches for &#8220;search_term&#8221; in <code>file.txt<\/code>.<\/td>\n<\/tr>\n<tr>\n<td><code>find<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/find-linux-command\/\">Searches for files<\/a> in a directory hierarchy.<\/td>\n<td><code>find . -name \"file.txt\"<\/code> finds all <code>file.txt<\/code> in the current directory and subdirectories.<\/td>\n<\/tr>\n<tr>\n<td><code>chmod<\/code><\/td>\n<td>Changes the file mode (permissions).<\/td>\n<td><code>chmod 755 script.sh<\/code> sets <code>script.sh<\/code> to be readable and executable by everyone, but only writable by the file owner.<\/td>\n<\/tr>\n<tr>\n<td><code>chown<\/code><\/td>\n<td>Changes file owner and group.<\/td>\n<td><code>chown user:group file.txt<\/code> changes the owner and group of <code>file.txt<\/code>.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Command Modifiers<\/h2>\n<h3>Modifier Flags for <code>ls<\/code><\/h3>\n<table>\n<thead>\n<tr>\n<th>Flag<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>-l<\/code><\/td>\n<td>Lists files in long format, showing detailed information.<\/td>\n<td><code>ls -l<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-a<\/code><\/td>\n<td>Includes directory entries whose names begin with a dot (.).<\/td>\n<td><code>ls -a<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-h<\/code><\/td>\n<td>Human-readable format, with file sizes.<\/td>\n<td><code>ls -lh<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-r<\/code><\/td>\n<td>Reverses the order of the sort.<\/td>\n<td><code>ls -lr<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-t<\/code><\/td>\n<td>Sorts by modification time, newest first.<\/td>\n<td><code>ls -lt<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Modifier Flags for <code>grep<\/code><\/h3>\n<table>\n<thead>\n<tr>\n<th>Flag<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>-i<\/code><\/td>\n<td>Ignores case distinctions in both the pattern and the input files.<\/td>\n<td><code>grep -i \"pattern\" file<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-v<\/code><\/td>\n<td>Inverts the match, showing lines that do not match the given pattern.<\/td>\n<td><code>grep -v \"pattern\" file<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-c<\/code><\/td>\n<td>Counts the number of lines that match the pattern.<\/td>\n<td><code>grep -c \"pattern\" file<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-n<\/code><\/td>\n<td>Prefixes each line of output with the line number within its input file.<\/td>\n<td><code>grep -n \"pattern\" file<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-r<\/code><\/td>\n<td>Recursively searches for the pattern in all files under the specified directory.<\/td>\n<td><code>grep -r \"pattern\" directory<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Modifier Flags for <code>mkdir<\/code><\/h3>\n<table>\n<thead>\n<tr>\n<th>Flag<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>-m<\/code><\/td>\n<td>Sets the file mode (permissions) of the newly <a href=\"https:\/\/ioflood.com\/blog\/mkdir-linux-command\/\">created directory<\/a>.<\/td>\n<td><code>mkdir -m 755 newdir<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-p<\/code><\/td>\n<td>Creates parent directories as needed and does not return an error if the <a href=\"https:\/\/ioflood.com\/blog\/bash-check-if-directory-exists\/\">directory already exists<\/a>.<\/td>\n<td><code>mkdir -p \/path\/to\/newdir<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Modifier Flags for <code>rm<\/code><\/h3>\n<table>\n<thead>\n<tr>\n<th>Flag<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>-r<\/code> or <code>-R<\/code><\/td>\n<td>Removes directories and their contents recursively.<\/td>\n<td><code>rm -r folderName<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-f<\/code><\/td>\n<td>Forces deletion without prompting for confirmation.<\/td>\n<td><code>rm -f filename<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-i<\/code><\/td>\n<td>Prompts for confirmation before deleting each file.<\/td>\n<td><code>rm -i filename<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Modifier Flags for <code>echo<\/code><\/h3>\n<table>\n<thead>\n<tr>\n<th>Flag<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>-n<\/code><\/td>\n<td>Do not output the trailing newline.<\/td>\n<td><code>echo -n \"text\"<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-e<\/code><\/td>\n<td>Enable interpretation of backslash escapes.<\/td>\n<td><code>echo -e \"Line 1\\nLine 2\"<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Modifier Flags for <code>cat<\/code><\/h3>\n<table>\n<thead>\n<tr>\n<th>Flag<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>-n<\/code><\/td>\n<td>Number all output lines.<\/td>\n<td><code>cat -n file<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-b<\/code><\/td>\n<td>Number non-empty output lines.<\/td>\n<td><code>cat -b file<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-s<\/code><\/td>\n<td>Suppress repeated empty output lines.<\/td>\n<td><code>cat -s file<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Modifier Flags for <code>touch<\/code><\/h3>\n<table>\n<thead>\n<tr>\n<th>Flag<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>-a<\/code><\/td>\n<td>Changes only the access time.<\/td>\n<td><code>touch -a file<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-m<\/code><\/td>\n<td>Changes only the modification time.<\/td>\n<td><code>touch -m file<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-c<\/code><\/td>\n<td>Does not create any files that do not already exist.<\/td>\n<td><code>touch -c file<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Modifier Flags for <code>cp<\/code><\/h3>\n<table>\n<thead>\n<tr>\n<th>Flag<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>-r<\/code> or <code>-R<\/code><\/td>\n<td>Recursively copies directories.<\/td>\n<td><code>cp -r sourceDir targetDir<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-i<\/code><\/td>\n<td>Prompts before overwrite.<\/td>\n<td><code>cp -i sourceFile targetFile<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-v<\/code><\/td>\n<td>Verbose mode, shows files as they are copied.<\/td>\n<td><code>cp -v sourceFile targetFile<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-a<\/code><\/td>\n<td>Archives files, copying all file attributes, including permissions and symbolic links.<\/td>\n<td><code>cp -a sourceDir targetDir<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Modifier Flags for <code>mv<\/code><\/h3>\n<table>\n<thead>\n<tr>\n<th>Flag<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>-i<\/code><\/td>\n<td>Prompts before overwrite.<\/td>\n<td><code>mv -i oldName newName<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-v<\/code><\/td>\n<td>Verbose mode, shows files as they are moved.<\/td>\n<td><code>mv -v oldLocation newLocation<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-u<\/code><\/td>\n<td>Moves only when the source file is newer than the destination file or when the destination file does not exist.<\/td>\n<td><code>mv -u oldFile newFile<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Modifier Flags for <code>find<\/code><\/h3>\n<table>\n<thead>\n<tr>\n<th>Flag<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>-name<\/code><\/td>\n<td>Search for files by name.<\/td>\n<td><code>find . -name \"filename.txt\"<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-type<\/code><\/td>\n<td>Search for files of a particular type (e.g., <code>d<\/code> for directories, <code>f<\/code> for regular files).<\/td>\n<td><code>find . -type f<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-perm<\/code><\/td>\n<td>Search for files with specific permissions.<\/td>\n<td><code>find . -perm 644<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-user<\/code><\/td>\n<td>Search for files owned by a specific user.<\/td>\n<td><code>find . -user username<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-mtime<\/code><\/td>\n<td>Search for files modified a certain number of days ago.<\/td>\n<td><code>find . -mtime +7<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-exec<\/code><\/td>\n<td>Execute a command on each file found.<\/td>\n<td><code>find . -type f -exec chmod 644 {} \\;<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-size<\/code><\/td>\n<td>Finds files of a specific size (e.g., <code>+50M<\/code> for files over 50MB, <code>-50M<\/code> for files under 50MB).<\/td>\n<td><code>find . -size +50M<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Modifier Flags for <code>chmod<\/code><\/h3>\n<table>\n<thead>\n<tr>\n<th>Flag<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>+<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/chmod-linux-command\/\">Adds a permission<\/a> to a file or directory.<\/td>\n<td><code>chmod +x file<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-<\/code><\/td>\n<td>Removes a permission from a file or directory.<\/td>\n<td><code>chmod -x file<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>r<\/code><\/td>\n<td>Read permission.<\/td>\n<td><code>chmod +r file<\/code> (adds read permission)<\/td>\n<\/tr>\n<tr>\n<td><code>w<\/code><\/td>\n<td>Write permission.<\/td>\n<td><code>chmod +w file<\/code> (adds write permission)<\/td>\n<\/tr>\n<tr>\n<td><code>x<\/code><\/td>\n<td>Execute permission.<\/td>\n<td><code>chmod +x file<\/code> (adds execute permission)<\/td>\n<\/tr>\n<tr>\n<td><code>u<\/code>, <code>g<\/code>, <code>o<\/code><\/td>\n<td>Set permissions for the user (u), group (g), or others (o).<\/td>\n<td><code>chmod u+x file.txt<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>a<\/code><\/td>\n<td>Set permissions for all users.<\/td>\n<td><code>chmod a+w file.txt<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Modifier Flags for <code>chown<\/code><\/h3>\n<table>\n<thead>\n<tr>\n<th>Flag<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>--recursive<\/code> or <code>-R<\/code><\/td>\n<td>Change file owner and group recursively.<\/td>\n<td><code>chown -R user:group directory<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>--verbose<\/code><\/td>\n<td>Output a diagnostic for every file processed.<\/td>\n<td><code>chown --verbose user file<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>--from<\/code><\/td>\n<td>Changes the owner and\/or group of each given file only if its current owner and\/or group match those specified.<\/td>\n<td><code>chown --from=current_user:current_group new_user:new_group file<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-c<\/code><\/td>\n<td>Like verbose but report only when a change is made.<\/td>\n<td><code>chown -c new_user file<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-v<\/code><\/td>\n<td>Verbose mode. Outputs a diagnostic for every file processed.<\/td>\n<td><code>chown -v new_user file<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Flags<\/h2>\n<table>\n<thead>\n<tr>\n<th>Flag<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>-e<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-exit-script\/\">Exit immediately<\/a> if a command exits with a non-zero status.<\/td>\n<\/tr>\n<tr>\n<td><code>-x<\/code><\/td>\n<td>Print commands and their arguments as they are executed.<\/td>\n<\/tr>\n<tr>\n<td><code>-u<\/code><\/td>\n<td>Treat unset variables as an error when substituting.<\/td>\n<\/tr>\n<tr>\n<td><code>-o pipefail<\/code><\/td>\n<td>Causes a pipeline to return the exit status of the last command in the pipe that failed.<\/td>\n<\/tr>\n<tr>\n<td><code>-v<\/code><\/td>\n<td>Print shell input lines as they are read.<\/td>\n<\/tr>\n<tr>\n<td><code>-n<\/code><\/td>\n<td>Read commands but do not execute them (syntax check).<\/td>\n<\/tr>\n<tr>\n<td><code>-f<\/code><\/td>\n<td>Disable filename expansion (globbing).<\/td>\n<\/tr>\n<tr>\n<td><code>-i<\/code><\/td>\n<td>Interactive mode &#8211; even if the input is not coming from a terminal.<\/td>\n<\/tr>\n<tr>\n<td><code>-c<\/code><\/td>\n<td>Read and execute commands from the following string.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Command Line Parameters<\/h2>\n<table>\n<thead>\n<tr>\n<th>Parameter<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>$0<\/code><\/td>\n<td>The filename of the current script.<\/td>\n<\/tr>\n<tr>\n<td><code>$1<\/code> to <code>$9<\/code><\/td>\n<td>The positional parameters, representing arguments passed to the script. <code>$1<\/code> is the first argument, <code>$2<\/code> is the second, and so on.<\/td>\n<\/tr>\n<tr>\n<td><code>${10}<\/code>, <code>${11}<\/code>, &#8230;<\/td>\n<td>For positional parameters beyond 9, curly braces are used to delimit the parameter number.<\/td>\n<\/tr>\n<tr>\n<td><code>$#<\/code><\/td>\n<td>The number of positional parameters passed to the script.<\/td>\n<\/tr>\n<tr>\n<td><code>$*<\/code><\/td>\n<td>All positional parameters seen as a single word. Useful when you need to pass all parameters to another command.<\/td>\n<\/tr>\n<tr>\n<td><code>$@<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-positional-parameters-variable\/\">All positional parameters<\/a> as separate strings. When quoted as <code>\"$@\"<\/code>, each parameter is quoted separately, which is useful for preserving spaces in parameters.<\/td>\n<\/tr>\n<tr>\n<td><code>$?<\/code><\/td>\n<td>The <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-special-variable-last-command-exit-status\/\">exit status of the last command<\/a> executed.<\/td>\n<\/tr>\n<tr>\n<td><code>$$<\/code><\/td>\n<td>The process ID (PID) of the current script.<\/td>\n<\/tr>\n<tr>\n<td><code>$!<\/code><\/td>\n<td>The PID of the last background command.<\/td>\n<\/tr>\n<tr>\n<td><code>$-<\/code><\/td>\n<td>The current options set for the shell.<\/td>\n<\/tr>\n<tr>\n<td><code>$IFS<\/code><\/td>\n<td>The Internal Field Separator that is used by the shell to determine how it recognizes fields, or word boundaries, in a string.<\/td>\n<\/tr>\n<tr>\n<td><code>shift<\/code><\/td>\n<td>Shifts positional parameters to the left by 1, decreasing the positional parameters count (<code>$#<\/code>). Useful for iterating over all arguments.<\/td>\n<\/tr>\n<tr>\n<td><code>set<\/code><\/td>\n<td>Used to <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/set-linux-command\/\">set or unset options and positional parameters<\/a>. <code>set --<\/code> can be used to overwrite all positional parameters.<\/td>\n<\/tr>\n<tr>\n<td><code>getopts<\/code><\/td>\n<td>A utility to parse positional parameters. Used in scripts to process <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-options\/\">command-line options and flags<\/a>.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Sorting Methods<\/h2>\n<table>\n<thead>\n<tr>\n<th>Technique\/Command<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>sort<\/code> Command<\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-sort\/\">Sorts the lines of a text file<\/a>. Supports numerical, reverse, and case-insensitive sorting among others.<\/td>\n<td><code>sort file.txt<\/code> for alphabetical sorting.<br \/><code>sort -n file.txt<\/code> for numerical sorting.<\/td>\n<\/tr>\n<tr>\n<td><code>sort<\/code> with Unique<\/td>\n<td>Combines sorting with removing duplicate lines.<\/td>\n<td><code>sort -u file.txt<\/code> to sort and remove duplicates.<\/td>\n<\/tr>\n<tr>\n<td>Array Sorting<\/td>\n<td>Bash does not natively support array sorting, but you can use <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-declare-array\/\">external commands or custom functions<\/a>.<\/td>\n<td><code>IFS=$'\\n' sorted=($(sort &lt;&lt;&lt;\"${array[*]}\"))<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>sort<\/code> with Reverse Order<\/td>\n<td>Sorts in reverse order.<\/td>\n<td><code>sort -r file.txt<\/code> for reverse alphabetical sorting.<\/td>\n<\/tr>\n<tr>\n<td><code>sort<\/code> with Custom Field<\/td>\n<td>Sorts based on a specific field or column.<\/td>\n<td><code>sort -k2,2 file.txt<\/code> to sort by the second column.<\/td>\n<\/tr>\n<tr>\n<td>Using <code>awk<\/code> for Sorting<\/td>\n<td>Preprocessing with <code>awk<\/code> before sorting, useful for complex data manipulation.<\/td>\n<td><code>awk '{print $2, $1}' file.txt | sort<\/code> to swap columns before sorting.<\/td>\n<\/tr>\n<tr>\n<td>Numeric Sort<\/td>\n<td>Specifically sorts lines by numerical value.<\/td>\n<td><code>sort -n file.txt<\/code><\/td>\n<\/tr>\n<tr>\n<td>Version Sort<\/td>\n<td>Sorts lines by version number, useful for filenames or version tags.<\/td>\n<td><code>sort -V files.txt<\/code> for version sorting.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Data Types<\/h2>\n<table>\n<thead>\n<tr>\n<th>Data Type<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>String<\/td>\n<td>Text or characters. Bash does not distinguish between strings and numbers, but strings can contain any character.<\/td>\n<td><code>str=\"Hello World\"<\/code><\/td>\n<\/tr>\n<tr>\n<td>Integer<\/td>\n<td>Whole numbers. Bash supports integer operations and comparisons.<\/td>\n<td><code>int=42; let \"int2 = int * 2\"<\/code><\/td>\n<\/tr>\n<tr>\n<td>Array<\/td>\n<td>Indexed or associative collections of values.<\/td>\n<td>Indexed: <code>arr=(one two three)<\/code><br \/>Associative: <code>declare -A assoc_arr=([\"key\"]=\"value\")<\/code><\/td>\n<\/tr>\n<tr>\n<td>Command Substitution<\/td>\n<td>Executes a command and substitutes its output.<\/td>\n<td><code>result=$(ls)<\/code><\/td>\n<\/tr>\n<tr>\n<td>Arithmetic Expansion<\/td>\n<td>Evaluates an arithmetic expression and substitutes the result.<\/td>\n<td><code>total=$((3 + 2))<\/code><\/td>\n<\/tr>\n<tr>\n<td>File Descriptor<\/td>\n<td>A reference to an open file. Bash scripts can read from and write to file descriptors.<\/td>\n<td><code>exec 3&lt;file.txt<\/code> (opens <code>file.txt<\/code> on FD 3)<\/td>\n<\/tr>\n<tr>\n<td>Here Document<\/td>\n<td>A type of redirection that feeds a command list or a script a literal block of text.<\/td>\n<td><code>cat &lt;&lt;EOF<\/code><br \/><code>Example text<\/code><br \/><code>EOF<\/code><\/td>\n<\/tr>\n<tr>\n<td>Here String<\/td>\n<td>A form of redirection that feeds a string into the standard input of a command.<\/td>\n<td><code>grep \"search\" &lt;&lt;&lt; \"search in this string\"<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Boolean Operations<\/h2>\n<table>\n<thead>\n<tr>\n<th>Concept<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><a href=\"https:\/\/ioflood.com\/blog\/bash-boolean\/\">Boolean Variables<\/a><\/td>\n<td>Bash doesn&#8217;t have a built-in Boolean type. Use strings or exit statuses to represent Booleans.<\/td>\n<td><code>is_true=\"true\"; if [ \"$is_true\" = \"true\" ]; then echo \"True\"; fi<\/code><\/td>\n<\/tr>\n<tr>\n<td>Conditional Execution<\/td>\n<td>Use <code>&amp;&amp;<\/code> for AND and <code>||<\/code> for OR in command sequences.<\/td>\n<td><code>[[ $a -eq $b ]] &amp;&amp; echo \"Equal\"<\/code> <br \/> <code>[[ $a -ne $b ]] || echo \"Not equal\"<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>if<\/code> Statements<\/td>\n<td>Evaluate conditions using <code>if<\/code>. Combine with <code>&amp;&amp;<\/code>, <code>||<\/code>, <code>-eq<\/code>, <code>-ne<\/code>, etc., for Boolean logic.<\/td>\n<td><code>if [[ $a -gt $b ]] &amp;&amp; [[ $c -eq 10 ]]; then echo \"True\"; fi<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>test<\/code> or <code>'[ ]'<\/code><\/td>\n<td>The <code>test<\/code> command or <code>'[ ]'<\/code> evaluates an expression and returns an exit status.<\/td>\n<td><code>test $a -lt $b; echo $?<\/code> <br \/> <code>[ $a -lt $b ]; echo $?<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>[[ ]]<\/code> for Advanced Conditions<\/td>\n<td>Advanced test command that allows for pattern matching and more complex expressions.<\/td>\n<td><code>[[ $a -gt $b &amp;&amp; $c -eq 10 ]]<\/code><\/td>\n<\/tr>\n<tr>\n<td>Exit Statuses<\/td>\n<td>Use the exit status of commands as Boolean expressions. A status of 0 (success) is true; non-zero is false.<\/td>\n<td><code>command; if [ $? -eq 0 ]; then echo \"Success\"; fi<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Function Structure<\/h2>\n<table>\n<thead>\n<tr>\n<th>Part<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Function Declaration<\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-function\/\">Defines a function<\/a>. Can use the <code>function<\/code> keyword or simply name the function directly.<\/td>\n<td><code>function myFunc() { echo \"Hello, World!\"; }<\/code> <br \/> <code>myFunc() { echo \"Hello, World!\"; }<\/code><\/td>\n<\/tr>\n<tr>\n<td>Calling a Function<\/td>\n<td>Executes the function by specifying its name followed by parentheses.<\/td>\n<td><code>myFunc()<\/code><\/td>\n<\/tr>\n<tr>\n<td>Passing Arguments<\/td>\n<td><a href=\"https:\/\/ioflood.com\/blog\/bash-function-arguments\/\">Functions can accept arguments<\/a> that are passed to them when called. Arguments within functions are accessed via <code>$1<\/code>, <code>$2<\/code>, etc.<\/td>\n<td><code>myFunc() { echo \"Hello, $1!\"; }<\/code><br \/><code>myFunc \"World\"<\/code><\/td>\n<\/tr>\n<tr>\n<td>Return Statement<\/td>\n<td>Exits the function with an optional return status (0-255). The return status can be captured with <code>$?<\/code>.<\/td>\n<td><code>myFunc() { return 1; }<\/code><br \/><code>myFunc<\/code><br \/><code>echo $?<\/code><\/td>\n<\/tr>\n<tr>\n<td>Local Variables<\/td>\n<td>Variables within a function that are only accessible within that function, declared with <code>local<\/code>.<\/td>\n<td><code>myFunc() { local localVar=\"I'm local\"; echo $localVar; }<\/code><\/td>\n<\/tr>\n<tr>\n<td>Function Output<\/td>\n<td>Functions can generate output that can be captured or used by the rest of the script.<\/td>\n<td><code>myFunc() { echo \"Function output\"; }<\/code><br \/><code>result=$(myFunc)<\/code><\/td>\n<\/tr>\n<tr>\n<td>Recursion<\/td>\n<td>Functions can call themselves, a technique known as recursion.<\/td>\n<td><code>recursiveFunc() { echo \"$1\"; if [ $1 -gt 0 ]; then recursiveFunc $(( $1 - 1 )); fi }<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Variables<\/h2>\n<table>\n<thead>\n<tr>\n<th>Concept<\/th>\n<th>Description<\/th>\n<th>Example<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><a href=\"https:\/\/ioflood.com\/blog\/bash-declare\/\">Variable Declaration and Assignment<\/a><\/td>\n<td>Assigning a value to a named variable.<\/td>\n<td><code>myVar=\"Hello World\"<\/code><\/td>\n<\/tr>\n<tr>\n<td>Environment Variables<\/td>\n<td>Predefined global variables used by the operating system and applications.<\/td>\n<td><code>echo $PATH<\/code><\/td>\n<\/tr>\n<tr>\n<td>Positional Parameters<\/td>\n<td><a href=\"https:\/\/ioflood.com\/blog\/bash-script-arguments\/\">Variables that represent the arguments passed to a script<\/a>.<\/td>\n<td><code>$1<\/code> for the first argument<\/td>\n<\/tr>\n<tr>\n<td>Special Variables<\/td>\n<td>Variables with specific functions in Bash.<\/td>\n<td><code>$$<\/code> for the script&#8217;s PID<\/td>\n<\/tr>\n<tr>\n<td>String Variables<\/td>\n<td>Operations on strings, such as extraction and concatenation.<\/td>\n<td>Concatenation: <code>greeting=\"Hello,\"; name=\"Alice\"; echo \"$greeting $name\"<\/code><\/td>\n<\/tr>\n<tr>\n<td>Numeric Variables<\/td>\n<td>Performing <a href=\"https:\/\/ioflood.com\/blog\/bash-math\/\">arithmetic operations<\/a>.<\/td>\n<td><code>let sum=5+3; echo $sum<\/code><\/td>\n<\/tr>\n<tr>\n<td>Arrays<\/td>\n<td>Working with indexed and <a href=\"https:\/\/ioflood.com\/blog\/bash-associative-array\/\">associative arrays<\/a>.<\/td>\n<td>Indexed: <code>arr=(one two three); echo ${arr[1]}<\/code><br \/>Associative: <code>declare -A arr; arr[\"key\"]=\"value\"; echo ${arr[\"key\"]}<\/code><\/td>\n<\/tr>\n<tr>\n<td>Read-only Variables<\/td>\n<td>Creating immutable variables.<\/td>\n<td><code>declare -r myVar=\"fixed value\"<\/code><\/td>\n<\/tr>\n<tr>\n<td>Exporting Variables<\/td>\n<td>Making variables available to subshell processes.<\/td>\n<td><code>export VAR=\"value\"<\/code><\/td>\n<\/tr>\n<tr>\n<td>Local Variables in Functions<\/td>\n<td>Variables scoped within a function.<\/td>\n<td><code>function myFunc() { local localVar=\"I'm local\"; }<\/code><\/td>\n<\/tr>\n<tr>\n<td>Variable Expansion<\/td>\n<td>Expanding variables to their values.<\/td>\n<td><code>echo \"Your home directory is: $HOME\"<\/code><\/td>\n<\/tr>\n<tr>\n<td>Indirect References<\/td>\n<td>Accessing the value of a variable using the name stored in another variable.<\/td>\n<td><code>refVar=\"myVar\"; echo \"${!refVar}\"<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Environment Variables<\/h2>\n<table>\n<thead>\n<tr>\n<th>Environment Variable<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>PATH<\/code><\/td>\n<td>A colon-separated list of directories in which the shell looks for commands.<\/td>\n<td><code>echo $PATH<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>HOME<\/code><\/td>\n<td>The current user&#8217;s home directory.<\/td>\n<td><code>echo $HOME<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>PWD<\/code><\/td>\n<td>The current working directory.<\/td>\n<td><code>echo $PWD<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>USER<\/code><\/td>\n<td>The name of the current user.<\/td>\n<td><code>echo $USER<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>HOSTNAME<\/code><\/td>\n<td>The name of the computer.<\/td>\n<td><code>echo $HOSTNAME<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>SHELL<\/code><\/td>\n<td>The path to the current user&#8217;s shell.<\/td>\n<td><code>echo $SHELL<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>EDITOR<\/code><\/td>\n<td>The default file editor to be used.<\/td>\n<td><code>export EDITOR=\/usr\/bin\/vim<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>LANG<\/code><\/td>\n<td>The current locale setting.<\/td>\n<td><code>echo $LANG<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>HISTSIZE<\/code><\/td>\n<td>The number of commands to remember in the command history.<\/td>\n<td><code>echo $HISTSIZE<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>UID<\/code><\/td>\n<td>The numeric user ID of the current user.<\/td>\n<td><code>echo $UID<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>TERM<\/code><\/td>\n<td>The current terminal emulation.<\/td>\n<td><code>echo $TERM<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Operators<\/h2>\n<h3>Arithmetic Operators<\/h3>\n<table>\n<thead>\n<tr>\n<th>Operator<\/th>\n<th>Description<\/th>\n<th>Syntax Example<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>+<\/code><\/td>\n<td>Addition<\/td>\n<td><code>expr $a + $b<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-<\/code><\/td>\n<td>Subtraction<\/td>\n<td><code>expr $a - $b<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>*<\/code><\/td>\n<td>Multiplication<\/td>\n<td><code>expr $a \\* $b<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>\/<\/code><\/td>\n<td>Division<\/td>\n<td><code>expr $a \/ $b<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>%<\/code><\/td>\n<td>Modulus<\/td>\n<td><code>expr $a % $b<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>**<\/code><\/td>\n<td>Exponentiation<\/td>\n<td><code>expr $a ** $b<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Assignment Operators<\/h3>\n<table>\n<thead>\n<tr>\n<th>Operator<\/th>\n<th>Description<\/th>\n<th>Syntax Example<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>=<\/code><\/td>\n<td>Assigns value from right side operands to left side operand<\/td>\n<td><code>a=$b<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>+=<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-append-to-array\/\">Addition assignment<\/a><\/td>\n<td><code>a+=b<\/code> (equivalent to <code>a=$a+$b<\/code>)<\/td>\n<\/tr>\n<tr>\n<td><code>-=<\/code><\/td>\n<td>Subtraction assignment<\/td>\n<td><code>a-=b<\/code> (equivalent to <code>a=$a-$b<\/code>)<\/td>\n<\/tr>\n<tr>\n<td><code>*=<\/code><\/td>\n<td>Multiplication assignment<\/td>\n<td><code>a*=b<\/code> (equivalent to <code>a=$a*$b<\/code>)<\/td>\n<\/tr>\n<tr>\n<td><code>\/=<\/code><\/td>\n<td>Division assignment<\/td>\n<td><code>a\/=b<\/code> (equivalent to <code>a=$a\/$b<\/code>)<\/td>\n<\/tr>\n<tr>\n<td><code>%=<\/code><\/td>\n<td>Modulus assignment<\/td>\n<td><code>a%=b<\/code> (equivalent to <code>a=$a%$b<\/code>)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Logical Operators<\/h3>\n<table>\n<thead>\n<tr>\n<th>Operator<\/th>\n<th>Description<\/th>\n<th>Syntax Example<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>&amp;&amp;<\/code><\/td>\n<td>Logical AND<\/td>\n<td><code>[ $a -lt 20 &amp;&amp; $b -gt 100 ]<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>||<\/code><\/td>\n<td>Logical OR<\/td>\n<td><code>[ $a -lt 20 || $b -gt 100 ]<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>!<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-not-equal\/\">Logical NOT<\/a><\/td>\n<td><code>[ !$a -lt 20 ]<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Relational Operators<\/h3>\n<table>\n<thead>\n<tr>\n<th>Operator<\/th>\n<th>Description<\/th>\n<th>Syntax Example<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>-eq<\/code><\/td>\n<td>Equal<\/td>\n<td><code>[ $a -eq $b ]<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-ne<\/code><\/td>\n<td>Not equal<\/td>\n<td><code>[ $a -ne $b ]<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-gt<\/code><\/td>\n<td>Greater than<\/td>\n<td><code>[ $a -gt $b ]<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-ge<\/code><\/td>\n<td>Greater than or equal to<\/td>\n<td><code>[ $a -ge $b ]<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-lt<\/code><\/td>\n<td>Less than<\/td>\n<td><code>[ $a -lt $b ]<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>-le<\/code><\/td>\n<td>Less than or equal to<\/td>\n<td><code>[ $a -le $b ]<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Data Structures<\/h2>\n<table>\n<thead>\n<tr>\n<th>Data Structure<\/th>\n<th>Characteristics<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Scalars<\/td>\n<td>Hold a single value, such as a number or a string.<\/td>\n<td><code>var=\"Hello World\"<\/code><\/td>\n<\/tr>\n<tr>\n<td>Indexed Arrays<\/td>\n<td>Ordered collections of values accessed by a numerical index.<\/td>\n<td><code>arr=(apple banana cherry)<\/code>; access with <code>${arr[1]}<\/code><\/td>\n<\/tr>\n<tr>\n<td>Associative Arrays<\/td>\n<td>Collections of key-value pairs accessed by string key. Requires Bash 4+.<\/td>\n<td><code>declare -A arr; arr[\"key\"]=\"value\"<\/code>; access with <code>${arr[key]}<\/code><\/td>\n<\/tr>\n<tr>\n<td>Strings<\/td>\n<td>A sequence of characters treated as a single value. <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-string-manipulation\/\">Extensive manipulation options<\/a>.<\/td>\n<td><code>str=\"Bash Scripting\"<\/code>; manipulate with <code>${str:0:4}<\/code><\/td>\n<\/tr>\n<tr>\n<td>Here Documents<\/td>\n<td>Direct a block of text into the input of a command.<\/td>\n<td><code>cat &lt;&lt;EOF &gt; file.txt<\/code><\/td>\n<\/tr>\n<tr>\n<td>Here Strings<\/td>\n<td>Direct a single line string into the input of a command.<\/td>\n<td><code>grep 'pattern' &lt;&lt;&lt; \"search in this string\"<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Statements and Loops<\/h2>\n<table>\n<thead>\n<tr>\n<th>Statement Type<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>if<\/code> Statement<\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-if-statement\/\">Evaluates a condition<\/a> and executes a block of code if the condition is true.<\/td>\n<td><code>if [ $a -eq $b ]; then echo \"Equal\"; fi<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>else<\/code><\/td>\n<td>Specifies the block of code that is executed if the <code>if<\/code> condition is false.<\/td>\n<td><code>if [ $a -eq $b ]; then echo \"Equal\"; else echo \"Not Equal\"; fi<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>elif<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-else-if\/\">Allows for multiple conditions<\/a> to be evaluated in an <code>if-else<\/code> block.<\/td>\n<td><code>if [ $a -eq $b ]; then echo \"Equal\"; elif [ $a -gt $b ]; then echo \"Greater\"; else echo \"Less\"; fi<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>case<\/code> Statement<\/td>\n<td>Selects a block of code to execute <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-case-statement\/\">based on the value of a variable<\/a>.<\/td>\n<td><code>case $var in pattern1) command1 ;; pattern2) command2 ;; esac<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>for<\/code> Loop<\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-for-loop\/\">Iterates over a list<\/a> of values.<\/td>\n<td><code>for i in {1..5}; do echo \"Number $i\"; done<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>while<\/code> Loop<\/td>\n<td>Executes a block of code <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-while-loop\/\">as long as a condition is true<\/a>.<\/td>\n<td><code>while [ $a -le 5 ]; do echo $a; a=$((a+1)); done<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>until<\/code> Loop<\/td>\n<td>Executes a block of code until a condition becomes true.<\/td>\n<td><code>until [ $a -gt 5 ]; do echo $a; a=$((a+1)); done<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>select<\/code> Statement<\/td>\n<td>Generates a menu from a list and executes code based on user selection.<\/td>\n<td><code>select ans in \"Choice1\" \"Choice2\"; do case $ans in Choice1) echo \"1\"; break;; Choice2) echo \"2\"; break;; esac done<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>break<\/code><\/td>\n<td>Exits from a loop.<\/td>\n<td><code>for i in {1..10}; do if [ $i -eq 5 ]; then break; fi; echo $i; done<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>continue<\/code><\/td>\n<td>Skips the rest of the loop iteration and proceeds with the next iteration.<\/td>\n<td><code>for i in {1..10}; do if [ $i -eq 5 ]; then continue; fi; echo $i; done<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Internal Field Separator (IFS)<\/h2>\n<table>\n<thead>\n<tr>\n<th>Concept<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>IFS<\/td>\n<td>Special <a href=\"https:\/\/ioflood.com\/blog\/bash-set-variable\/\">shell variable<\/a> used to determine how Bash recognizes word boundaries. By default, it is set to space, tab, and newline.<\/td>\n<td>N\/A<\/td>\n<\/tr>\n<tr>\n<td>Customizing IFS for Input Field Separation<\/td>\n<td>Temporarily adjusting IFS to split input into fields based on a custom delimiter.<\/td>\n<td><code>IFS=',' read -r first second third &lt;&lt;&lt; \"a,b,c\"<\/code><\/td>\n<\/tr>\n<tr>\n<td>Restoring Original IFS<\/td>\n<td>It&#8217;s good practice to restore IFS to its original state after modifying it to avoid unexpected behavior in script execution.<\/td>\n<td><code>oldIFS=\"$IFS\"; IFS=','; ...; IFS=\"$oldIFS\"<\/code><\/td>\n<\/tr>\n<tr>\n<td>Using IFS in Loops<\/td>\n<td>Customizing IFS to loop through lines or entries separated by specific delimiters.<\/td>\n<td><code>IFS=$'\\n'; for line in $(cat file.txt); do echo \"$line\"; done<\/code><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/ioflood.com\/blog\/bash-split-string-into-array\/\">Splitting Strings into Arrays<\/a><\/td>\n<td>Utilizing IFS to split a string into an array based on a delimiter.<\/td>\n<td><code>IFS=':'; read -ra ADDR &lt;&lt;&lt; \"$PATH\"; echo \"${ADDR[0]}\"<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>String Manipulation<\/h2>\n<table>\n<thead>\n<tr>\n<th>Method<\/th>\n<th>Description<\/th>\n<th>Example<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Concatenation<\/td>\n<td>Combining strings.<\/td>\n<td><code>str1=\"Hello,\"; str2=\"World\"; echo \"$str1 $str2\"<\/code><\/td>\n<\/tr>\n<tr>\n<td>Substring<\/td>\n<td>Extracting <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-substring\/\">parts of a string<\/a>.<\/td>\n<td><code>${string:position:length}<\/code><\/td>\n<\/tr>\n<tr>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-replace-string\/\">Replace<\/a><\/td>\n<td>Replacing part of a string.<\/td>\n<td><code>${string\/substring\/replacement}<\/code><\/td>\n<\/tr>\n<tr>\n<td>Length<\/td>\n<td>Getting the <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-length-of-string\/\">length of a string<\/a>.<\/td>\n<td><code>${#string}<\/code><\/td>\n<\/tr>\n<tr>\n<td>Uppercase Conversion<\/td>\n<td>Converting a string to uppercase.<\/td>\n<td><code>${string^^}<\/code><\/td>\n<\/tr>\n<tr>\n<td>Lowercase Conversion<\/td>\n<td><a href=\"https:\/\/ioflood.com\/blog\/bash-lowercase\/\">Converting a string<\/a> to lowercase.<\/td>\n<td><code>${string,,}<\/code><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/ioflood.com\/blog\/bash-trim-whitespace\/\">Trim Whitespaces<\/a><\/td>\n<td>Trimming whitespaces from both ends of a string.<\/td>\n<td><code>string=\"  some text  \"; trimmed=$(echo -e \"$string\" | sed 's\/^[[:space:]]*\/\/;s\/[[:space:]]*$\/\/')<\/code><\/td>\n<\/tr>\n<tr>\n<td>Split String into Array<\/td>\n<td>Splitting a string into an array using a delimiter.<\/td>\n<td><code>IFS='delimiter' read -ra ADDR &lt;&lt;&lt; \"$str\"; echo \"${ADDR[0]}\"<\/code><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/ioflood.com\/blog\/bash-if-string-contains\/\">Check if String Contains Substring<\/a><\/td>\n<td>Checking if a string contains a specific substring.<\/td>\n<td><code>[[ $str == *\"$substring\"* ]] &amp;&amp; echo \"Found\" || echo \"Not found\"<\/code><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/ioflood.com\/blog\/strings-linux-command\/\">Extracting Strings<\/a> Using Regex<\/td>\n<td>Extracting parts of a string based on a <a href=\"https:\/\/ioflood.com\/blog\/bash-regex\/\">regular expression<\/a>.<\/td>\n<td><code>[[ $str =~ regex ]] &amp;&amp; echo \"${BASH_REMATCH[1]}\"<\/code><\/td>\n<\/tr>\n<tr>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-split-string\/\">Splitting Strings<\/a><\/td>\n<td>Dividing a string into parts based on a delimiter.<\/td>\n<td><code>IFS='delimiter'; read -ra parts &lt;&lt;&lt; \"$str\"; echo \"${parts[0]}\"<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Regex &amp; Pattern Matching<\/h2>\n<table>\n<thead>\n<tr>\n<th>Concept<\/th>\n<th>Description<\/th>\n<th>Example<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>grep<\/code><\/td>\n<td>Searches for patterns in files or input.<\/td>\n<td><code>grep 'pattern' filename<\/code><br \/><code>echo \"text\" | grep 'pattern'<\/code> | Use <code>-E<\/code> for extended regex, <code>-i<\/code> for case-insensitive search.<\/td>\n<\/tr>\n<tr>\n<td><code>sed<\/code><\/td>\n<td><a href=\"https:\/\/ioflood.com\/blog\/sed-linux-command\/\">Stream editor for filtering and transforming text<\/a>.<\/td>\n<td><code>sed 's\/pattern\/replacement\/' filename<\/code> | Useful for find-and-replace operations with regex.<\/td>\n<\/tr>\n<tr>\n<td><code>awk<\/code><\/td>\n<td><a href=\"https:\/\/ioflood.com\/blog\/awk-linux-command\/\">Text processing<\/a> language that supports regex.<\/td>\n<td><code>awk '\/pattern\/ { action }' filename<\/code> | Great for data extraction and reporting.<\/td>\n<\/tr>\n<tr>\n<td>Pattern Expansion<\/td>\n<td>Bash feature for filename matching using wildcards.<\/td>\n<td><code>ls *.txt<\/code> | <code>*<\/code>, <code>?<\/code>, and <code>[abc]<\/code> are common wildcards.<\/td>\n<\/tr>\n<tr>\n<td><code>*<\/code> (PE)<\/td>\n<td>Matches any string of characters.<\/td>\n<td><code>ls *<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>?<\/code> (PE)<\/td>\n<td>Matches any single character.<\/td>\n<td><code>ls ?.txt<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>[abc]<\/code> (PE)<\/td>\n<td>Matches any one character in the specified set.<\/td>\n<td><code>ls [a-c].txt<\/code><\/td>\n<\/tr>\n<tr>\n<td>Extended Globbing<\/td>\n<td>Additional pattern matching capabilities in Bash.<\/td>\n<td><code>ls !(exclude).txt<\/code> | Enable with <code>shopt -s extglob<\/code>. Patterns like <code>?<\/code> and <code>*<\/code> become available.<\/td>\n<\/tr>\n<tr>\n<td><code>?<\/code> (EG)<\/td>\n<td>Matches zero or one occurrence of the pattern.<\/td>\n<td><code>ls ?(a).txt<\/code> (with <code>shopt -s extglob<\/code>)<\/td>\n<\/tr>\n<tr>\n<td><code>*<\/code> (EG)<\/td>\n<td>Matches zero or more occurrences of the pattern.<\/td>\n<td><code>ls *(a).txt<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>+<\/code> (EG)<\/td>\n<td>Matches one or more occurrences of the pattern.<\/td>\n<td><code>ls +(a).txt<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>@<\/code> (EG)<\/td>\n<td>Matches exactly one of the patterns.<\/td>\n<td><code>ls @(a).txt<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>!<\/code> (EG)<\/td>\n<td>Matches anything except the pattern.<\/td>\n<td><code>ls !(a).txt<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Date and Time<\/h2>\n<table>\n<thead>\n<tr>\n<th>Command\/Technique<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>date<\/code><\/td>\n<td>Display or <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/date-linux-command\/\">set the system&#8217;s date and time<\/a>.<\/td>\n<td><code>date \"+%Y-%m-%d %H:%M:%S\"<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>sleep<\/code><\/td>\n<td>Pauses script execution for a specified time.<\/td>\n<td><code>sleep 5<\/code><\/td>\n<\/tr>\n<tr>\n<td>Arithmetic with <code>date<\/code><\/td>\n<td>Calculations with dates to find past or future dates.<\/td>\n<td><code>date -d \"yesterday\"<\/code><br \/><code>date -d \"+1 week\"<\/code><\/td>\n<\/tr>\n<tr>\n<td>Epoch Time (<code>date +%s<\/code>)<\/td>\n<td>Use seconds since the Unix Epoch for calculations.<\/td>\n<td><code>date +%s<\/code><br \/><code>date -d @1609459200<\/code><\/td>\n<\/tr>\n<tr>\n<td>Using <code>date<\/code> with Files<\/td>\n<td>Set or compare file timestamps.<\/td>\n<td><code>touch -d \"1 Jan 2020\" file.txt<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>timedatectl<\/code><\/td>\n<td>(systemd only) View\/set system time and date.<\/td>\n<td><code>timedatectl set-timezone Asia\/Tokyo<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>hwclock<\/code><\/td>\n<td>Access or adjust the hardware clock (RTC).<\/td>\n<td><code>hwclock --show<\/code><\/td>\n<\/tr>\n<tr>\n<td>Bash Scripting with <code>printf<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-date-format\/\">Format date<\/a> and time outputs in scripts.<\/td>\n<td><code>printf \"Today is %s.\\n\" \"$(date '+%Y-%m-%d')\"<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Text Color and Formatting<\/h2>\n<table>\n<thead>\n<tr>\n<th>Code\/Command<\/th>\n<th>Type<\/th>\n<th>Description<\/th>\n<th>Example Usage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>30<\/code>&#8211;<code>37<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-color\/\">Text Color<\/a><\/td>\n<td>Set text color (30: Black, &#8230;, 37: White)<\/td>\n<td><code>\\e[32mGreen Text\\e[0m<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>40<\/code>&#8211;<code>47<\/code><\/td>\n<td>Background Color<\/td>\n<td>Set background color (40: Black, &#8230;, 47: White)<\/td>\n<td><code>\\e[44mBlue Background\\e[0m<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>0<\/code><\/td>\n<td>Formatting<\/td>\n<td>Reset all attributes<\/td>\n<td><code>\\e[0mReset<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>1<\/code><\/td>\n<td>Formatting<\/td>\n<td>Bold text<\/td>\n<td><code>\\e[1mBold Text\\e[0m<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>2<\/code><\/td>\n<td>Formatting<\/td>\n<td>Dim text<\/td>\n<td><code>\\e[2mDim Text\\e[0m<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>4<\/code><\/td>\n<td>Formatting<\/td>\n<td>Underlined text<\/td>\n<td><code>\\e[4mUnderlined Text\\e[0m<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>5<\/code><\/td>\n<td>Formatting<\/td>\n<td>Blinking text<\/td>\n<td><code>\\e[5mBlinking Text\\e[0m<\/code> (Note: may not work in all terminals)<\/td>\n<\/tr>\n<tr>\n<td><code>7<\/code><\/td>\n<td>Formatting<\/td>\n<td>Reverse colors<\/td>\n<td><code>\\e[7mReversed Colors\\e[0m<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>8<\/code><\/td>\n<td>Formatting<\/td>\n<td>Hidden text<\/td>\n<td><code>\\e[8mHidden Text\\e[0m<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>tput<\/code><\/td>\n<td>Command<\/td>\n<td>Portable way to use terminal capabilities<\/td>\n<td><code>tput setaf 1; echo \"Red Text\"; tput sgr0<\/code><\/td>\n<\/tr>\n<tr>\n<td>Custom Function<\/td>\n<td>Technique<\/td>\n<td>Simplify color usage in scripts<\/td>\n<td>Define a function: <code>red_text() { echo -e \"\\e[31m$1\\e[0m\"; }<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Common Errors<\/h2>\n<table>\n<thead>\n<tr>\n<th>Error<\/th>\n<th>Description &amp; Cause<\/th>\n<th>Solution<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>Command Not Found<\/code><\/td>\n<td>The <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-command-not-found\/\">system can&#8217;t locate the script or command<\/a> being executed. Caused by a typo, the command not being installed, or a PATH issue.<\/td>\n<td>Check for typos, ensure the command is installed, or verify the PATH variable.<\/td>\n<\/tr>\n<tr>\n<td><code>Unary Operator Expected<\/code><\/td>\n<td>Bash <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-unary-operator-expected\/\">expected a unary operator<\/a> (<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/z-flag-in-bash\/\">like <code>-z<\/code><\/a> or <code>-n<\/code>), often due to missing quotes around a variable that might become an empty string.<\/td>\n<td>Ensure variables are quoted when used in test expressions.<\/td>\n<\/tr>\n<tr>\n<td><code>Bad Substitution<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-bad-substitution\/\">Syntax error<\/a>, usually because of a typo or misuse of brace expansion or variable substitution features.<\/td>\n<td>Check the syntax for brace expansions or variable references. Use <code>${var}<\/code> for variables.<\/td>\n<\/tr>\n<tr>\n<td><code>sudo: Command Not Found<\/code><\/td>\n<td>The <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-sudo-command-not-found\/\"><code>sudo<\/code> command isn&#8217;t installed<\/a> on the system, common in minimal installations or certain Docker images.<\/td>\n<td>Install <code>sudo<\/code> with the package manager, e.g., <code>apt-get install sudo<\/code> for Debian\/Ubuntu.<\/td>\n<\/tr>\n<tr>\n<td><code>Permission Denied<\/code><\/td>\n<td>Lack of execution permissions on a script or attempt to access a file\/directory <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-permission-denied\/\">without the necessary permissions<\/a>.<\/td>\n<td>Use <code>chmod<\/code> to add execute permission to the script <code>chmod +x script.sh<\/code> or correct file permissions.<\/td>\n<\/tr>\n<tr>\n<td><code>No Such File or Directory<\/code><\/td>\n<td>The script or the <a class=\"wp-editor-md-post-content-link\" href=\"\">file path specified doesn&#8217;t exist<\/a>, possibly due to a wrong path or a typo.<\/td>\n<td>Check the path and the filename for typos. <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/f-flag-in-bash\/\">Ensure the file exists<\/a> in the specified location.<\/td>\n<\/tr>\n<tr>\n<td><code>Syntax Error Near Unexpected Token<\/code><\/td>\n<td>Syntax error caused by incorrect use of Bash syntax, like a misplaced or missing <code>fi<\/code> for an <code>if<\/code> statement.<\/td>\n<td>Review the script for syntax errors, paying close attention to loops, conditionals, and function definitions.<\/td>\n<\/tr>\n<tr>\n<td><code>Integer Expression Expected<\/code><\/td>\n<td>A test command or condition expects an integer, but is given a string or a variable that doesn&#8217;t hold an integer.<\/td>\n<td>Ensure that variables used in arithmetic tests are integers or quoted if they might be empty.<\/td>\n<\/tr>\n<tr>\n<td><code>Too Many Arguments<\/code><\/td>\n<td>A test expression receives more arguments than expected, often due to unquoted variables expanding into multiple words.<\/td>\n<td>Quote variables in test expressions to prevent word splitting, especially when a variable could contain spaces.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Script Comments<\/h2>\n<table>\n<thead>\n<tr>\n<th>Topic<\/th>\n<th>Description<\/th>\n<th>Example<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-comment\/\">Single-line Comment<\/a><\/td>\n<td>Uses the <code>#<\/code> symbol to mark the remainder of the line as a comment.<\/td>\n<td><code># This is a comment<\/code><\/td>\n<\/tr>\n<tr>\n<td>Multi-line Comment<\/td>\n<td>Simulated using <code>: '...'<\/code> <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-multiline-comment\/\">for multiple lines<\/a> not directly supported.<\/td>\n<td><code>: 'This is a multi-line comment'<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Script Output<\/h2>\n<table>\n<thead>\n<tr>\n<th>Topic<\/th>\n<th>Description<\/th>\n<th>Example<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/echo-linux-command\/\">Echo<\/a><\/td>\n<td>Uses <code>echo<\/code> command to <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-print\/\">display a line of text\/string<\/a>.<\/td>\n<td><code>echo \"Hello World\"<\/code><\/td>\n<\/tr>\n<tr>\n<td>Printf<\/td>\n<td>Uses <code>printf<\/code> for <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-printf\/\">formatted output<\/a>, similar to the C function.<\/td>\n<td><code>printf \"Name: %s\\nAge: %d\\n\" \"John\" 25<\/code><\/td>\n<\/tr>\n<tr>\n<td>Here Document<\/td>\n<td>Directs a block of text into an input stream.<\/td>\n<td><code>cat &lt;&lt;EOF &gt;file.txt\\nText\\nEOF<\/code><\/td>\n<\/tr>\n<tr>\n<td>Redirection<\/td>\n<td>Redirects output to a file or another command using <code>&gt;<\/code>, <code>&gt;&gt;<\/code>, or <code>|<\/code>.<\/td>\n<td><code>echo \"Text\" &gt; file.txt<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Networking Commands<\/h2>\n<table>\n<thead>\n<tr>\n<th>Command<\/th>\n<th>Description<\/th>\n<th>Example<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>ping<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/ping-linux-command\/\">Checks the network connectivity<\/a> to another host.<\/td>\n<td><code>ping google.com<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>ifconfig<\/code> \/ <code>ip<\/code><\/td>\n<td>Displays or <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/install-ip-command-linux\/\">configures the network interface<\/a> settings.<\/td>\n<td><code>ip addr show<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>netstat<\/code><\/td>\n<td>Displays network connections, routing tables, and interface statistics.<\/td>\n<td><code>netstat -tuln<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>curl<\/code> \/ <code>wget<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/curl-linux-command\/\">Downloads files<\/a> from the network.<\/td>\n<td><code>curl -O http:\/\/example.com\/file.txt<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>ssh<\/code><\/td>\n<td>Securely connects to a remote machine.<\/td>\n<td><code>ssh user@host<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>scp<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/scp-linux-command\/\">Securely copies files<\/a> between hosts.<\/td>\n<td><code>scp file.txt user@host:\/path<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>nslookup<\/code> \/ <code>dig<\/code><\/td>\n<td><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/dig-linux-command\/\">Queries DNS<\/a> to obtain domain name or IP address mapping.<\/td>\n<td><code>dig example.com<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Debugging and Error Handling<\/h2>\n<table>\n<thead>\n<tr>\n<th>Topic<\/th>\n<th>Description<\/th>\n<th>Example<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>set -e<\/code><\/td>\n<td>Exits the script if any command returns a non-zero exit status.<\/td>\n<td><code>set -e<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>set -u<\/code><\/td>\n<td>Treats unset variables and parameters as an error.<\/td>\n<td><code>set -u<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>set -x<\/code><\/td>\n<td>Displays commands and their arguments as they are executed.<\/td>\n<td><code>set -x<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>trap<\/code><\/td>\n<td>Catches or intercepts a signal and executes a specified command.<\/td>\n<td><code>trap 'echo \"Error\"' ERR<\/code><\/td>\n<\/tr>\n<tr>\n<td>Custom Error Messages<\/td>\n<td>Uses conditional statements to check command success and displays custom error messages.<\/td>\n<td><code>command || echo \"Command failed\"<\/code><\/td>\n<\/tr>\n<tr>\n<td>Debugging Tools<\/td>\n<td>Utilizes external tools like <code>bashdb<\/code> for <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-exit-codes\/\">debugging Bash scripts<\/a>.<\/td>\n<td>N\/A (usage depends on the tool installation)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Bash Sample Script &amp; Syntax<\/h2>\n<p>In this section, we&#8217;ll walk through a straightforward Bash script that demonstrates how different Bash scripting concepts come together. The following script will provide practical syntax examples, followed by <code>echo<\/code> statements to showcase what the codeblocks would output. Before the Script, we will instruct you on how to prepare an environment, so that you may run the code yourself!<\/p>\n<h3>Setting Up Your Environment<\/h3>\n<p>To prepare your environment for running Bash scripts, follow these streamlined steps:<\/p>\n<ol>\n<li><strong>Choose an IDE or Editor:<\/strong><br \/>\n     Pick your preferred editor like Visual Studio Code, Atom, Sublime Text, or a terminal-based editor like <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/vim-linux-command\/\">Vim<\/a> or Emacs for writing Bash scripts.<\/p>\n<\/li>\n<li>\n<p><strong>Ensure Bash is Available:<\/strong><br \/>\n    <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/install-bash-shell-linux\/\">Linux<\/a>\/macOS: Bash is typically pre-installed.<br \/>\n    Windows: Install Windows Subsystem for Linux (WSL), Git Bash, or Cygwin.<\/p>\n<\/li>\n<li>\n<p><strong>Create and Open Your Bash Script:<\/strong><br \/>\n    Open your editor, create a new file, paste the Bash script, and save it with a .sh extension, e.g., myscript.sh.<\/p>\n<\/li>\n<li>\n<p><strong>Set Execute Permissions:<\/strong><br \/>\n    Open a terminal, navigate to your script&#8217;s directory, and run: chmod +x myscript.sh.<\/p>\n<\/li>\n<li>\n<p><strong>Run Your Script:<\/strong><br \/>\n    In the terminal, execute the script by typing: .\/myscript.sh [arg1].<br \/>\n    <em>Note: This script expects an integer as a command-line argument, provide it as such:<\/em><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"language-bash line-numbers\">.\/myscript.sh [integer]\n<\/code><\/pre>\n<p>That&#8217;s it! You&#8217;re ready to execute Bash scripts.<\/p>\n<h3>Bash Sample Script<\/h3>\n<p>Below, we present a sample Bash script designed to showcase a range of Bash scripting techniques. This example should also provide insight into scripting best practices and how various commands can be used together. Refer to this segment to understand more about how the commands and concepts previously discussed are applied in actual coding scenarios.<\/p>\n<pre><code class=\"language-bash line-numbers\">#!\/bin\/bash\n# The above line is called a shebang. It tells the system this script should\n# be executed using Bash, the Bourne Again SHell, regardless of which shell \n# the user might be using. It specifies the path to the Bash interpreter.\n\n# Variable assignment\nname=\"World\"\necho \"Hello, $name\"\n# Output: Hello, World\n\n# Command-line Parameters\nnumber=$1\n\nif [ $number -eq 10 ]; then # Compare the parameter to 10\n    echo \"Your number is equal to 10.\"\nelif [ $number -lt 10 ]; then\n    echo \"Your number is less than 10.\"\nelse\n    echo \"Your number is greater than 10.\"\nfi\n# Output will depend on number used when calling the script\n# If the number \"5\" was passed, output would be:\n# Your number is less than 10.\n\n# printf for formatted output\nname=\"Alice\"\nage=30\nprintf \"Name: %s, Age: %d\\n\" \"$name\" \"$age\"\n# Output: Name: Alice, Age: 30\n\n# Environment Variables\necho \"Your home directory is: $HOME\"\n# Outputs the path to the user's home directory\n\n# Setting a new environment variable\nexport MY_VAR=\"Hello World\"\necho $MY_VAR\n# Outputs: Hello World\n\n# Using an environment variable in a command\nmkdir \"$MY_VAR\"\n# Creates a new directory named \"Hello World\"\n\n# String Concatenation\nstr1=\"Hello\"\nstr2=\"World\"\nconcatenatedStr=\"$str1, $str2!\"\necho \"Concatenated string: $concatenatedStr\"\n# Output: Concatenated string: Hello, World!\n\n# String Length\nstr=\"Hello World\"\nlength=${#str}\necho \"Length of '$str': $length\"\n# Output: Length of 'Hello World': 11\n\n# Substring Extraction\n# Extracting 'World' from 'Hello World'\nextractedStr=${str:6:5}\necho \"Extracted substring: $extractedStr\"\n# Output: Extracted substring: World\n\n# Case Conversion\n# Converting to uppercase\nupperStr=${str^^}\necho \"Uppercase conversion: $upperStr\"\n# Output: Uppercase conversion: HELLO WORLD\n\n# Replace in String\n# Replacing 'World' with 'Bash'\nreplacedStr=${str\/World\/Bash}\necho \"Replaced String: $replacedStr\"\n# Output: Replaced String: Hello Bash\n\n# Split string based on delimiter (space in this example)\nstring=\"one two three\"\nIFS=' ' read -r -a str_array &lt;&lt;&lt; \"$string\"\necho \"First element after split: ${str_array[0]}\" # Outputs \"First element after split: one\"\n\n# Array usage\nfruits=(\"apple\" \"banana\" \"cherry\")\necho \"First fruit: ${fruits[0]}\" # Output: First fruit: apple\n\n# Associative array\ndeclare -A capitals\ncapitals[\"France\"]=\"Paris\"\ncapitals[\"Germany\"]=\"Berlin\"\necho \"The capital of France is: ${capitals[France]}\" # Output: The capital of France is: Paris\n\n# Reading a file line by line\nwhile IFS= read -r line; do\n  echo \"Line: $line\"\ndone &lt; myfile.txt # Output: Lines from myfile.txt\n\n# Check if a file exists\nfile=\"myfile.txt\"\nif [ -f \"$file\" ]; then\n  echo \"$file exists.\"\nelse\n  echo \"$file does not exist.\"\nfi # Output depends on if myfile.txt exists\n\n# Sorting lines of text in a file alphabetically\necho -e \"banana\\napple\\nfig\" &gt; fruits.txt\nsort fruits.txt\n# This will output:\n# apple\n# banana\n# fig\n\n# Numerical sort with -n flag\necho -e \"10\\n2\\n1\" &gt; numbers.txt\nsort -n numbers.txt\n# This will output:\n# 1\n# 2\n# 10\n\n# Using Here Document to create a configuration file\ncat &lt;&lt; EOF &gt; myconfig.conf\n# My Application Configuration File\nHOST=localhost\nPORT=8080\nEOF\n\necho \"Configuration file created with the following content:\"\ncat myconfig.conf\n\n# Text color and formatting w\/ ANSI escape codes\necho -e \"\\e[31mThis text is red\\e[0m\" # Red text\necho -e \"\\e[1;34mThis text is bold and blue\\e[0m\" # Bold and blue text\n\ncurrent_date=$(date)\necho \"Current date and time: $current_date\"\n\n# Show date and time one week later\ndate_one_week_later=$(date -d \"$current_date + 1 week\") # '-d' flag used for date manipulation, allowing for manipulation like \"1 week\" to be performed\"\necho \"Date and time one week later: $date_one_week_later\"\n\n# Conditional statement\nif [ \"$name\" = \"World\" ]; then\n  echo \"The condition is true.\"\nelse\n  echo \"The condition is false.\"\nfi \n# Output: The condition is true.\n\n# Case statement\ncolor=\"red\"\ncase $color in\n  red)\n    echo \"Red color selected.\"\n    ;;\n  blue)\n    echo \"Blue color selected.\"\n    ;;\n  *)\n    echo \"Unknown color.\"\n    ;;\nesac # Output: Red color selected.\n\n# For Loop\nfor i in {1..3}; do\n  echo \"Loop iteration: $i\"\ndone \n# Output: Loop iteration: 1 (then 2, then 3)\n\n# While loop\ncount=3\nwhile [ $count -gt 0 ]; do\n  echo \"Countdown: $count\"\n  ((count--))\ndone \n# Output: Countdown: 3 (then 2, then 1)\n\n# Using Break and Continue in Loops\nfor i in {1..5}; do # Loop through numbers 1 to 5\n  if [ \"$i\" -eq 3 ]; then\n    echo \"Skipping number $i\"\n    continue # Skip the rest of the loop at 3 and continue with the next iteration\n  fi\n  if [ \"$i\" -eq 4 ]; then\n    echo \"Stopping at number $i\"\n    break # Exit the loop at number 4\n  fi\n  echo \"Number $i\" # Will output \"Number 1\" then \"Number 2\"\ndone\n\n# Use of parameters ($@)\necho \"Script parameters: $@\"\n# When running: .\/script.sh param1 param2\n# Output: Script parameters: param1 param2\n\n# Assignment Operators and Arithmetic\na=10\nb=0\necho \"Initial value of a: $a\" # 10\n\n# Assignment\na=$b\necho \"Assigned value of b to a: $a\" # Value of b\n\n# Addition assignment\n((a+=5))\necho \"After addition assignment: $a\" # 5\n\n# Subtraction assignment\n((a-=3))\necho \"After subtraction assignment: $a\" # 2\n\n# Multiplication assignment\n((a*=2))\necho \"After multiplication assignment: $a\" # 4\n\n# Logical Operators\na=true\nb=false\n\n# Logical AND\nif [[ $a &amp;&amp; $b ]]; then\n    echo \"Both are true.\"\nelse\n    echo \"a AND b is false.\"\nfi # a AND b is false.\n\n# Logical OR\nif [[ $a || $b ]]; then\n    echo \"At least one is true.\"\nelse\n    echo \"Both are false.\"\nfi # At least one is true.\n\n# Logical NOT\nif [[ ! $b ]]; then\n    echo \"b is not true.\"\nelse\n    echo \"b is true.\"\nfi # b is not true.\n\n# Relational Operators\na=10\nb=20\n\nif [ $a -eq $b ]; then\n    echo \"a is equal to b.\"\nelif [ $a -ne $b ]; then\n    echo \"a is not equal to b.\" # This will be executed\nfi\n\nif [ $a -lt $b ]; then\n    echo \"a is less than b.\" # This will be executed\nelif [ $a -gt $b ]; then\n    echo \"a is greater than b.\"\nfi\n\nif [ $a -le $b ]; then\n    echo \"a is less than or equal to b.\" # This will be executed\nelif [ $a -ge $b ]; then\n    echo \"a is greater than or equal to b.\"\nfi\n\n# Simple Regex Matching in Conditional\nif [[ \"Hello World!\" =~ ^Hello ]]; then # Checks if the string starts with \"Hello\"\n  echo \"Pattern found in string\" # This will be the output\nelse\n  echo \"Pattern not found in string\"\nfi\n\n# Extracting Parts of String Using Regex\nversionString=\"Version: 5.0.17\"\nif [[ $versionString =~ Version:\\ ([0-9]+)\\.([0-9]+)\\.([0-9]+) ]]; then\n  majorVersion=${BASH_REMATCH[1]}\n  minorVersion=${BASH_REMATCH[2]}\n  patchVersion=${BASH_REMATCH[3]}\n  echo \"Major: $majorVersion, Minor: $minorVersion, Patch: $patchVersion\" # Major: 5, Minor: 0, Patch: 17\nfi\n\n# Pattern Matching with Globbing\nfiles=(*.sh)\necho \"Shell script files: ${files[@]}\" # Lists .sh files in the current directory\n\n# Using Extended Globbing\nshopt -s extglob # Enable extended globbing\nfiles=(!(*.sh))\necho \"Non-shell script files: ${files[@]}\" # Lists files not ending with .sh\nshopt -u extglob # Disable extended globbing\n\n# Flags and Modifier Flags\n# Use 'set -e' to exit the script when any command fails\nset -e\necho \"Set -e: Exit on first error. Next command will fail, exiting the script early.\"\ncat nonexistentfile.txt\n# Use 'set +e' to disable exit on first error\nset +e\n\n# Use 'set -u' to treat unset variables as an error\nset -u\necho \"Set -u: Treating unset variables as an error.\"\necho $UNSET_VARIABLE\n# Use 'set +u' to disable treating unset variables as an error\nset +u\n\n# Redirecting stderr to stdout and filtering through grep\nls valid_file.txt non_existent_file.txt 2&gt;&amp;1 | grep \"No such file\" || echo \"One or more files do not exist.\"\n\n# Using the -f flag with grep to read patterns from a file\necho \"Error\" &gt; patterns.txt\ngrep -f patterns.txt log.txt || echo \"Pattern not found in log.txt.\"\n\n# Command chaining with logical AND (&amp;&amp;) and OR (||)\nmkdir temp_directory &amp;&amp; echo \"Directory created successfully.\" || echo \"Failed to create directory.\"\n\n# Redirecting command output to a file while checking for command success\ncp source.txt destination.txt &amp;&amp; echo \"Copy successful.\" &gt; operation_status.txt || echo \"Copy failed.\" &gt; operation_status.txt\n\n# Using the exec command with redirection to globally redirect script output\nexec 3&gt;&amp;1 4&gt;&amp;2 # Saving file descriptors\nexec 1&gt;log_all_output.txt 2&gt;&amp;1 # Redirecting all output to log file\necho \"This output will be logged in the file.\"\nexec 1&gt;&amp;3 2&gt;&amp;4 # Restoring file descriptors\n\n# Function definition and call\ngreet() {\n  local person=\"$1\" # Local variable\n  echo \"Hello, $person\"\n}\ngreet \"Alice\" # Output: Hello, Alice\n\n# A function to display basic system information and store it into a log file\nsystem_info() {\n  echo \"System Information Report:\"\n\n  # Display current date and time\n  echo \"Current Date and Time: $(date)\"\n\n  # Show system uptime\n  echo \"System Uptime: $(uptime -p)\"\n\n  # Disk space usage\n  echo \"Disk Space Usage:\"\n  df -h | grep \"^\/dev\" # Shows disk space usage for devices starting with \/dev\n\n  # Memory usage\n  echo \"Memory Usage:\"\n  free -h # Display human-readable memory usage\n}\n\n# Calling the system_info function and redirecting output to a file with a timestamp\nsystem_info | tee \"system_info_$(date \"+%Y-%m-%d_%H-%M-%S\").txt\"\n\n# File and Directory Manipulation\n# Define directory and file names\ndirName=\"exampleDir\"\nfileName=\"exampleFile.txt\"\n\n# Create a new directory\nmkdir $dirName\n\n# Navigate into the directory\ncd $dirName\n\n# Create a new file and write to it\necho \"This is a sample text.\" &gt; $fileName\n\n# Display the content of the file\necho \"Contents of $fileName:\"\ncat $fileName\n\n# Navigate back to the original directory\ncd ..\n\n# Clean up: Remove the directory and its contents\nrm -r $dirName\n\n# Error Handling and Conditional Execution\n# Attempt to read from a non-existent file and check exit status\ncat non_existent_file.txt\nif [ $? -ne 0 ]; then\n  echo \"Failed to read file.\" # This message is shown if the file doesn't exist.\nfi\n\n# Using conditional execution to echo \"Error\" if a command fails\nls non_existent_directory || echo \"Error: Directory does not exist.\"\n\n# Using &amp;&amp; for success execution\necho \"Checking for \/tmp directory existence...\" &amp;&amp; ls \/tmp || echo \"Error: \/tmp directory does not exist.\"\n\n# Explicitly setting an exit status\nfalse\nif [ $? -eq 0 ]; then\n  echo \"Command succeeded.\"\nelse\n  echo \"Command failed.\"\nfi\n<\/code><\/pre>\n<p>The example code provided above showcased a variety of Bash scripting techniques, from basic command execution to more complex structures like <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-loop\/\">loops<\/a> and <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ioflood.com\/blog\/bash-conditional\/\">conditionals<\/a>. Remember, the reference section is there to support you; use it to revisit any concepts covered in the script or to clarify details as you experiment with Bash on your own!<\/p>\n<h2>Conclusion<\/h2>\n<p>In this article, we&#8217;ve equipped you with a handy Bash command reference and demonstrated these concepts through a practical code example. It&#8217;s our hope that these tools will bolster your Bash scripting journey, enhancing both your understanding and efficiency. As you move forward, we wish you the best of luck with your future Bash endeavors. Happy scripting!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Managing dedicated servers and performing system administration tasks at IOFLOOD requires a solid understanding of Bash syntax to efficiently automate processes and troubleshoot issues. Drawing from our experience in server management and software deployment, we&#8217;ve compiled this comprehensive Bash reference guide. This Bash Cheat Sheet is your concise companion in the vast world of Bash [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":18547,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[124,3,121],"tags":[],"class_list":["post-18427","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash","category-linux","category-programming-coding","cat-124-id","cat-3-id","cat-121-id","has_thumb"],"_links":{"self":[{"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts\/18427","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/comments?post=18427"}],"version-history":[{"count":65,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts\/18427\/revisions"}],"predecessor-version":[{"id":19736,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts\/18427\/revisions\/19736"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/media\/18547"}],"wp:attachment":[{"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/media?parent=18427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/categories?post=18427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/tags?post=18427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}