TestingDocs.com
    Software Testing website
    • Automation
      • Selenium
      • JBehave Framework
    • Tutorials
      • MySQL Tutorials
      • Testlink
      • Maven
      • Git
    • IDEs
      • IntelliJ IDEA
      • Eclipse
    • Flowcharts
      • Flowgorithm
      • Raptor
    • About

    Linux

    Writing a Simple Hello World Bash Script

    Overview

    In this post let us learn how to write a simple bash script. We will use vim editor to write the script. The script prints the “Hello World” message on the console.

    Steps to create a Bash Script

    Lets us name the script myscript.sh

    Open the command shell and type the following.

    # vi myscript.sh

    To enter edit mode type the key i

    Enter the script code as shown below:

    #!/bin/bash
    
    echo "Hello World \n"

     

    Type :wq<Enter> to save and quit the vi editor screen.

    Now you need to provide execute permission to the script so that you can execute the script.

    # chmod +x myscript.sh

    Execute the script.

    #./myscript.sh

     

    That’s it. You have successfully executed a simple bash script. Successful script run would print Hello World message on the console screen.

    A common problem while editing files with vim editor is that you may encounter the following error.

    Found a swap file by the name “.myscript.sh.swp”
    While opening file “myscript.sh”

    (1) Another program may be editing the same file. If this is the case,
    be careful not to end up with two different instances of the same
    file when making changes. Quit, or continue with caution.
    (2) An edit session for this file crashed.
    If this is the case, use “:recover” or “vim -r myscript.sh”
    to recover the changes (see “:help recovery”).
    If you did this already, delete the swap file “.myscript.sh.swp”
    to avoid this message.

    Simply follow the instruction to recover the previous changes or Enter to discard the changes.

    Related Posts

    Linux Mint Download

    Linux /

    Install Linux Mint Cinnamon [64-bit]

    Android Studio Setup Wizard

    Linux /

    Customization of Android Development Environment

    Download Android Studio

    Linux /

    Download Android Studio Package on Linux

    gedit Text Editor Ubuntu

    Linux /

    gedit Text Editor in Linux

    Download Ubuntu Desktop

    Linux /

    Create Ubuntu Bootable USB Pendrive on Windows

    ‹ Kali Linux Distribution› Popular Linux Distributions

    Recent Posts

    • ChatGPT Subscription Plans
    • Stellar Converter for Database
    • Stellar Log Analyzer for MySQL
    • Stellar Repair for MySQL
    • ChatGPT Capabilities
    • How to secure your SQL Database: Tips and Tricks
    • ChatGPT4 Conversational AI Features
    • Shaping the Future of Development: Exploring Key Trends in Software Engineering
    • Improving Java Performance with Multithreading
    • Open-source Vector Databases

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com