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

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

Linux /

Linux Files

‹ GNU General Public License› Popular Linux Distributions

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version