Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

BASH Shell: Input and Output Redirection, Environment Variables, and Shell Scripts, Slides of Advanced Operating Systems

An in-depth exploration of working with the bash shell, focusing on command input and output redirection, manipulating common shell environment variables, creating and exporting new shell variables, editing environment files, and creating and executing basic shell scripts. It covers the purpose and nature of shell scripts, creating and executing basic shell scripts, effectively using common decision constructs, and various redirection techniques.

Typology: Slides

2012/2013

Uploaded on 04/24/2013

banani
banani ๐Ÿ‡ฎ๐Ÿ‡ณ

4.3

(3)

91 documents

1 / 46

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter 8
Working with the BASH Shell
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e

Partial preview of the text

Download BASH Shell: Input and Output Redirection, Environment Variables, and Shell Scripts and more Slides Advanced Operating Systems in PDF only on Docsity!

Chapter 8

Working with the BASH Shell

Objectives

  • Redirect the input and output of a command
  • Identify and manipulate common shell environment variables
  • Create and export new shell variables
  • Edit environment files to create variables upon shell startup

Command Input and Output

  • BASH shell responsible for:
    • Providing user interface
    • Interpreting commands
    • Manipulating command input and output
      • Provided user specifies certain shell metacharacters with command
  • File descriptors: Numeric labels that define command input and command output

Command Input and Output (continued)

  • Standard Input (stdin): File descriptor representing command input
  • Standard Output (stdout): File descriptor representing command output
  • Standard Error (stderror): File descriptor representing command error messages

Redirection

  • Redirect stdout and stderr from terminal screen to a file - Use โ€œ>โ€ shell metacharacter - Can redirect stdout and stderr to separate files
  • Use separate filenames for stdout and stderr
  • Otherwise, use the &
  • Ex: .$ls โ€“ l /etc/host /etc/h >jj 2>&

Redirection (continued)

  • Redirecting stdin to a file:
    • Use โ€œ<โ€œ shell metacharacter
  • tr command: Replace characters in a file sent via stdin
  • tr accepts files not file name so you need to use input redirection
  • The shell always clears the content of the file specified in the output redirection

Pipes

  • Send stdout of one command to another command as stdin
  • Pipe: String of commands connected by โ€œ|โ€ metacharacters - stdout on left, stdin on right
  • Commonly used to reduce amount of information displayed on terminal screen (using grep)

Pipes (continued)

Figure 8-2: Piping information from one command to another

Pipes (continued)

Figure 8-3: Piping several commands

Pipes (continued)

Table 8-2: Common filter commands

Shell Variables

  • Variable: A reserved portion of memory containing accessible information
  • BASH shell has several variables in memory
  • Environment variables: Contain information that system and programs access regularly
  • User-defined variables: Custom variables define by users
  • Special variables
    • Useful when executing commands and creating new files and directories

Environment Variables

  • set command: Lists environment variables and current values
  • echo command: View contents a specified variable - Use $ shell metacharacter
  • Changing value of a variable:
    • Specify variable name followed by equal sign (=) and new value

Environment Variables (continued)

Table 8-3 (continued): Common BASH environment variables

Environment Variables (continued)

Table 8-3 (continued): Common BASH environment variables