What is the result of the following shell command? read -p enter a line of text: line

A shell script is a text file that contains a sequence of commands for a UNIX-based operating system. It is called a shell script because it combines a sequence of commands, that would otherwise have to be typed into the keyboard one at a time, into a single script. The shell is the operating system's command-line interface (CLI) and interpreter for the set of commands that are used to communicate with the system.

A shell script is usually created for command sequences in which a user has a need to use repeatedly in order to save time. Like other programs, the shell script can contain parameters, comments and subcommands that the shell must follow. Users initiate the sequence of commands in the shell script by simply entering the file name on a command line.

In the DOS operating system, a shell script is called a batch file. In IBM's mainframe VM operating systems, it's called an EXEC.

How shell scripting works

The basic steps involved with shell scripting are writing the script, making the script accessible to the shell and giving the shell execute permission.

Shell scripts contain ASCII text and are written using a text editor, word processor or graphical user interface (GUI). The content of the script is a series of commands in a language that can be interpreted by the shell. Functions that shell scripts support include loops, variables, if/then/else statements, arrays and shortcuts. Once complete, the file is saved typically with a .txt or .sh extension and in a location that the shell can access.

Types of shells

In Unix and Linux, the two major types of shell scripts are:

  1. Bourne again shells (BASH)- BASH is the default shell for Unix version 7. The character for prompting a bourne again shell is $.
  2. C shells- A C shell is run in a text terminal window and is able to easily read file commands. The character for prompting a C shell is %.

Examples of shell script applications

Using a shell script is most useful for repetitive tasks that may be time consuming to execute by typing one line at a time. A few examples of applications shell scripts can be used for include:

  • Automating the code compiling process.
  • Running a program or creating a program environment.
  • Completing batch
  • Manipulating files.
  • Linking existing programs together.
  • Executing routine backups.
  • Monitoring a system.

Advantages and disadvantages of shell scripts

Shell scripting is meant to be simple and efficient. It uses the same syntax in the script as it would on the shell command line, removing any interpretation issues. Writing code for a shell script is also faster and requires less of learning curve than other programming languages.

However, if there is an error in a shell script, this can prove to be extremely costly if left unnoticed. Additionally, differing platforms associated with shell scripting may not be compatible. Shell scripts can also be slower to execute than individual commands.

This was last updated in September 2019

Continue Reading About shell script

  • Jenkins Git environment variables list: A working shell script example
  • Jenkins environment variables list for shell script build jobs
  • Learn shell scripts: A sys admin's guide to automation
  • Advanced shell scripting for IT ops professionals
  • Writing Secure Shell Scripts

Dig Deeper on Data center ops, monitoring and management

  • What is the result of the following shell command? read -p enter a line of text:  line
    batch file

    What is the result of the following shell command? read -p enter a line of text:  line

    By: Rahul Awati

  • What is the result of the following shell command? read -p enter a line of text:  line
    bash (Bourne again shell)

    What is the result of the following shell command? read -p enter a line of text:  line

    By: Peter Loshin

  • What is the result of the following shell command? read -p enter a line of text:  line
    command-line interface (CLI)

    What is the result of the following shell command? read -p enter a line of text:  line

    By: Peter Loshin

  • What is the result of the following shell command? read -p enter a line of text:  line
    A look at the main differences of Bourne shell vs. Bash

    What is the result of the following shell command? read -p enter a line of text:  line

    By: Jack Wallen

How do I read a text file line by line in shell?

We can use the read command to read the contents of a file line by line. We use the -r argument to the read command to avoid any backslash-escaped characters. In the following example, we can see that we have an iteration over a file line by line and we store the contents of a single line in the variable “line“.

What does read command do in shell script?

The read command reads one line from standard input and assigns the values of each field in the input line to a shell variable using the characters in the IFS (Internal Field Separator) variable as separators.

Which command displays the text of the file line by line?

Use the pg command to read the files named in the File parameter and writes them to standard output one screen at a time. Use the more or page command to display continuous text one screen at a time. Use the cat command to read each File parameter in sequence and writes it to standard output.

What does command line shell mean?

The command-line shell, sometimes called the command prompt or the terminal, is a tool that lets you control your computer using only textual commands. It offers a lot of power and simplicity (simplicity is different from ease of use).