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

Linux

Shell Script to Display Name in Linux

Introduction

In this tutorial, we will learn how to write a simple script in the Linux operating system. The most important use of scripting is Automation. Bash scripting allows you to automate tasks that you run commands using the console. We can even schedule the scripts in crontab to run unattended automatically.

Simple Bash Script

Let’s write a simple bash script. We use Open Suse Linux distribution in this tutorial.

Go to konsole or Terminal

Create a directory to hold your scripts.

$> mkdir scripts

Change to the directory and create a file with .sh extension.

$> cd scripts/

$> touch sampleScript.sh

 

 

To edit the file, we use vi editor. Type the following command.

$> vi sampleScript.sh

Enter into the insert mode by hitting i key button.

Type the sample script code as shown below. The script prompts the user for a name and then echos

it back to the console with a greeting.

Hit the escape button and:wq to save and exit the vi editor.

 

#!/bin/bash
# This is a simple Linux script
# Greeting
echo -e "Enter your name:= "
read fullName
echo "Hello! $fullName"

 

 

Try to run the script file with ./

> ./sampleScript.sh
bash: ./sampleScript.sh: Permission denied

Notice the Permission denied error message.

chmod command

We need to provide the execution permission for the user to execute the shell script.

> chmod +x sampleScript.sh
> ls -l sampleScript.sh
-rwxr-xr-x 1 suri users 123 Apr 21 05:43 sampleScript.sh

Once you have granted the execute permission with the chmod command. We can execute the shell script.

 

 

That’s it. We have run a simple shell script on a Linux box!

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

‹ File Commands in Linux› Linux Directories

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