Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Programming»Bash Shell»How to Include Bash Script in other Bash Script

    How to Include Bash Script in other Bash Script

    By RahulJuly 26, 20161 Min Read

    Bash scripts are very useful for doing work easier. It also helps for task automation. This tutorial will help you to how to include bash script in other bash script.

    Advertisement

    Create Sample Scripts

    For example, I am creating two scripts, first is config.sh which contains some variables. Second script is our main script main.sh, which includes first script and used variables defines there.

    Step 1 – First Script (config.sh)

    USERNAME="rahul"
    EMAIL="[email protected]"
    

    Main Script (main.sh)

    #!/bin/bash
    
    # Including config.sh, set filename with proper path.
    
    source config.sh  
    
    echo Welcome ${USERNAME}!
    echo Your email is ${EMAIL}.
    

    Step 2 – Execute Script

    Let’s execute main.sh using terminal and watch the results.

    [[email protected] ~]$ sh main.sh
    
    Welcome rahul!
    Your email is [email protected].
    

    bash script
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    A User’s Guide to Understanding Redirection Operators in Bash

    What are the difference between SH and BASH

    What are the difference between SH and BASH?

    An In-depth Guide to Using the =~ Operator in Bash

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Setting and Getting the Default Timezone in Python
    • What is Media Access Control (MAC) Address?
    • What is Cross-Site Scripting (XSS)?
    • What is Content Security Policy (CSP)?
    • A User’s Guide to Understanding Redirection Operators in Bash
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.