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

    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

    ‹ File Commands in Linux› Linux Directories

    Recent Posts

    • ChatGPT Plans Free and PlusChatGPT Subscription Plans
    • Stellar Converter for Database ToolStellar Converter for Database
    • Stellar MySQL Log AnalyzerStellar Log Analyzer for MySQL
    • Stellar Repair for MySQLStellar Repair for MySQL
    • ChatGPT IntroductionChatGPT Capabilities
    • How to secure your SQL Database: Tips and Tricks
    • ChatGPT4 Conversational AI FeaturesChatGPT4 Conversational AI Features
    • Trends in Software EngineeringShaping the Future of Development: Exploring Key Trends in Software Engineering
    • Java PerformanceImproving Java Performance with Multithreading
    • QDrant Vector DatabaseOpen-source Vector Databases
    • Difference between PHP and JavaScript?
    • Bing AI Browser Web ContentBing Conversation Styles
    • ChatGPT PreviewChatGPT Introduction
    • Open Source AI Frameworks TensorFlowOpen Source AI Frameworks
    • Artificial Intelligence Tools

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com