{"id":48,"date":"2026-10-14T05:51:03","date_gmt":"2026-10-14T05:51:03","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2015\/06\/17\/shell-scripting-bash-training-2\/"},"modified":"2026-10-14T05:51:03","modified_gmt":"2026-10-14T05:51:03","slug":"shell-scripting-bash-training-2","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/shell-scripting-bash-training-2\/","title":{"rendered":"Shell Scripting (Bash) Training Roadmap: From First Script to Automation"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><em>Originally published on 2015-06-17; fully revised and updated.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This page is a structured roadmap for engineers and administrators who want to learn Bash scripting for day-to-day DevOps work. You will see the full learning sequence, practical commands, and how to move from simple scripts to production-friendly automation.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2015\/06\/shell-bash-training.png\" alt=\"Shell Bash scripting training\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Original registration link from the source post: <a href=\"events\/register\/index.html\" target=\"_blank\" rel=\"noopener\">DevOps Training Registration<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What this Bash training covers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The original post provided a module list. Reorganized into a modern sequence, the course covers Linux shell foundations, Git basics, core Bash syntax, control flow, parameters, functions, string operations, and operational execution patterns such as background jobs and cron.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Shell and Linux fundamentals<\/li><li>Git fundamentals for script versioning<\/li><li>Creating and running shell scripts safely<\/li><li>Variables, input, output, and redirection<\/li><li>Conditionals, loops, and control statements<\/li><li>Functions and reusable script design<\/li><li>Parameters, <code>shift<\/code>, and <code>getopts<\/code><\/li><li>String handling, pattern matching, and arrays<\/li><li>Execution modes: foreground, background, nohup, cron<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Learning flow from basics to automation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use this sequence to avoid common learning gaps. Each stage builds directly on the previous one.<\/p>\n\n\n\n<pre class=\"mermaid\">\nflowchart TD\n    A[Linux shell basics] --> B[Git fundamentals]\n    B --> C[First Bash scripts]\n    C --> D[Variables and input output]\n    D --> E[If tests and return codes]\n    E --> F[Loops and case statements]\n    F --> G[Parameters and getopts]\n    G --> H[Functions strings arrays]\n    H --> I[Run with nohup cron and exec]\n    I --> J[Debug harden and maintain]\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Curriculum breakdown by module<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Foundation modules<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Why shell scripting and where it fits in DevOps workflows<\/li><li>Linux internals relevant to scripting<\/li><li>Prerequisites and terminal habits<\/li><li>Git setup, basic operations, and GitHub usage<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Core Bash scripting modules<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Script creation, shebang usage, and naming conventions<\/li><li>Variables, quoting, and reading user input<\/li><li>If\/then\/else logic, conditional expressions, and arithmetic tests<\/li><li>Input\/output with <code>echo<\/code>, <code>printf<\/code>, and stream redirection<\/li><li>Control flow with <code>while<\/code>, <code>until<\/code>, <code>for<\/code>, <code>break<\/code>, <code>continue<\/code>, and <code>case<\/code><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Advanced and operational modules<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Integer variables, arithmetic expressions, readonly\/exported variables, arrays<\/li><li>Handling parameters with special variables, <code>shift<\/code>, and <code>getopts<\/code><\/li><li>Functions and reusable script structure<\/li><li>String slicing, search\/replace, default values, and regex patterns<\/li><li>Execution options including background runs, <code>nohup<\/code>, <code>exec<\/code>, <code>at<\/code>, and <code>cron<\/code><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Hands-on Bash examples to practice<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These examples match the topics in the curriculum and are suitable for lab practice.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php language-bash\"><span class=\"hljs-comment\">#!\/usr\/bin\/env bash<\/span>\nset -euo pipefail\n\nnote_file=<span class=\"hljs-string\">\"${HOME}\/notes.txt\"<\/span>\nread -r -p <span class=\"hljs-string\">\"Enter note: \"<\/span> note\nprintf <span class=\"hljs-string\">\"%s | %s\\n\"<\/span> <span class=\"hljs-string\">\"$(date +%F\\ %T)\"<\/span> <span class=\"hljs-string\">\"$note\"<\/span> &gt;&gt; <span class=\"hljs-string\">\"$note_file\"<\/span>\n<span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"Saved to $note_file\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php language-bash\"><span class=\"hljs-comment\">#!\/usr\/bin\/env bash<\/span>\nset -euo pipefail\n\nlog_file=<span class=\"hljs-string\">\"${1:-app.log}\"<\/span>\n\n<span class=\"hljs-keyword\">if<\/span> &#91;&#91; -f <span class=\"hljs-string\">\"$log_file\"<\/span> ]]; then\n  <span class=\"hljs-keyword\">if<\/span> grep -q <span class=\"hljs-string\">\"ERROR\"<\/span> <span class=\"hljs-string\">\"$log_file\"<\/span>; then\n    <span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"Errors found in $log_file\"<\/span>\n  <span class=\"hljs-keyword\">else<\/span>\n    <span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"No errors found in $log_file\"<\/span>\n  fi\n<span class=\"hljs-keyword\">else<\/span>\n  <span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"File not found: $log_file\"<\/span> &gt;&amp;<span class=\"hljs-number\">2<\/span>\n  <span class=\"hljs-keyword\">exit<\/span> <span class=\"hljs-number\">1<\/span>\nfi<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php language-bash\"><span class=\"hljs-comment\">#!\/usr\/bin\/env bash<\/span>\nset -euo pipefail\n\nfile=<span class=\"hljs-string\">\"\"<\/span>\ncount=<span class=\"hljs-number\">1<\/span>\n\n<span class=\"hljs-keyword\">while<\/span> getopts <span class=\"hljs-string\">\":f:n:h\"<\/span> opt; <span class=\"hljs-keyword\">do<\/span>\n  <span class=\"hljs-keyword\">case<\/span> <span class=\"hljs-string\">\"$opt\"<\/span> in\n    f) file=<span class=\"hljs-string\">\"$OPTARG\"<\/span> ;;\n    n) count=<span class=\"hljs-string\">\"$OPTARG\"<\/span> ;;\n    h)\n      <span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"Usage: $0 -f FILE &#91;-n COUNT]\"<\/span>\n      <span class=\"hljs-keyword\">exit<\/span> <span class=\"hljs-number\">0<\/span>\n      ;;\n    :)\n      <span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"Option -$OPTARG requires an argument\"<\/span> &gt;&amp;<span class=\"hljs-number\">2<\/span>\n      <span class=\"hljs-keyword\">exit<\/span> <span class=\"hljs-number\">1<\/span>\n      ;;\n    \\?)\n      <span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"Invalid option: -$OPTARG\"<\/span> &gt;&amp;<span class=\"hljs-number\">2<\/span>\n      <span class=\"hljs-keyword\">exit<\/span> <span class=\"hljs-number\">1<\/span>\n      ;;\n  esac\ndone\n\nshift <span class=\"hljs-string\">\"$((OPTIND - 1))\"<\/span>\n<span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"file=$file count=$count remaining_args=$*\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Ways to run scripts in development and operations<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Method<\/th><th>Best for<\/th><th>Caveat<\/th><th>Example<\/th><\/tr><\/thead><tbody><tr><td>Direct execution<\/td><td>Normal script usage with shebang<\/td><td>Needs execute permission<\/td><td><code>.\/script.sh<\/code><\/td><\/tr><tr><td>Invoke with bash<\/td><td>Quick tests without chmod<\/td><td>May bypass intended interpreter in shebang<\/td><td><code>bash script.sh<\/code><\/td><\/tr><tr><td>source (dot command)<\/td><td>Loading functions or environment variables into current shell<\/td><td>Changes affect current shell session<\/td><td><code>source .\/env.sh<\/code><\/td><\/tr><tr><td>nohup and background<\/td><td>Long tasks that should continue after logout<\/td><td>No built-in scheduling\/retry policy<\/td><td><code>nohup .\/job.sh &gt; job.log 2&gt;&amp;1 &amp;<\/code><\/td><\/tr><tr><td>cron scheduling<\/td><td>Recurring automation<\/td><td>Runs with minimal environment<\/td><td><code>0 2 * * * \/opt\/scripts\/backup.sh<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs language-bash\">chmod +x script.sh\n.\/script.sh\nbash script.sh\nsource .\/env.sh\nnohup .\/job.sh &gt; job.log 2&gt;&amp;1 &amp;\ncrontab -e<\/code><\/span><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Best practices and common pitfalls<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Start scripts with <code>#!\/usr\/bin\/env bash<\/code> and use strict mode (<code>set -euo pipefail<\/code>) when appropriate.<\/li><li>Quote variables to prevent word-splitting and globbing bugs.<\/li><li>Check exit codes and handle failures explicitly.<\/li><li>Use <code>shellcheck<\/code> during development to catch common issues early.<\/li><li>For cron jobs, set required environment variables inside the script.<\/li><li>Keep scripts in Git and review changes like application code.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">This revised page preserves the original training intent while giving you a practical, execution-focused path for learning and applying Bash scripting in DevOps environments.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This revised Bash training guide turns the original topic list into a practical learning roadmap. It shows what to study, how topics connect, and which commands to practice for real-world scripting.<\/p>\n","protected":false},"author":1,"featured_media":3459,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[8],"tags":[99,137,1675,1679,140,91,101,103,102,95,93,100,97,94,92,139,138,1676,136,1678,1677,1674,105,96,104,98],"class_list":["post-48","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-training","tag-bangalore","tag-bash","tag-bash-course","tag-bash-scripting-course","tag-bash-training","tag-build","tag-continuous-integration","tag-courses","tag-delivery","tag-devops","tag-engineer","tag-hyderabad","tag-india","tag-online","tag-release","tag-scripting","tag-shell","tag-shell-course","tag-shell-scripting","tag-shell-scripting-course","tag-shell-scripting-training","tag-shell-training","tag-trainer","tag-training","tag-tutorials","tag-usa"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/48","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=48"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/48\/revisions"}],"predecessor-version":[{"id":79287,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/48\/revisions\/79287"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/3459"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=48"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=48"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=48"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}