Analyzing PATH Directories

LinuxLinuxIntermediate
Practice Now

Introduction

As a junior system administrator, you've been tasked with creating a simple report on the directories in your Linux system's PATH. This task will help you understand the structure of the PATH variable and practice using basic command sequences and pipelines.

Create the PATH Analysis Script

Your task is to create a script named path_analysis.sh that processes the $PATH variable and reports on the directories it contains.

Tasks

  1. Create a script named path_analysis.sh in the ~/project directory. If the script already exists, you can modify it.
  2. Use command sequences and pipelines to:
    • Display the full PATH.
    • List each directory in the PATH on a separate line.
    • Count the total number of directories in the PATH.
  3. Format the output as shown in the example below.

Requirements

Your script must meet these requirements:

  • Use only command sequences (&&, ||) and pipelines (|) for control flow.
  • Utilize basic commands like echo, tr, wc, and grep for text processing.
  • Format the output to match the example below.

Hits

  1. The path_analysis.sh file for editing is located in the ~/project directory in the left side directory tree.
  2. Open a new terminal window from the top Terminal menu to run the script file with the bash command.
Terminal running path analysis script

Example

Your script's output should resemble this format:

Example script output format
Full PATH:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Directories in PATH:
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin

Total directories in PATH: 6
โœจ Check Solution and Practice

Summary

By completing this challenge, you've demonstrated your ability to:

  1. Process environment variables using basic command sequences and pipelines.
  2. Combine multiple Unix commands to analyze and present data.
  3. Format and present data in a structured output.

This exercise introduces you to processing system variables, a common task in system administration. The skills you've practiced are fundamental to shell scripting and command-line data processing in Unix-like systems.