TCM Security Academy Notes - by syselement
🏠 Home BlogGitHub📚 Buy Me a Book
  • TCM Security Academy Notes
  • Courses
    • TCM - Linux 101
      • 1. Introduction
        • Linux Distributions
        • Installing Linux
      • 2. Command Line
        • Intro to Command Line
        • Getting help on the Command Line
        • Command Line Arguments and Options
        • Reading Text Files
      • 3. File System
        • Filesystem Hierarchy Standard
        • Devices, Partitions and Mounting
        • Absolute and Relative Paths
        • Files and Directories
        • Paths, Filenames and Text Files
        • Filesystem Links
        • Archiving and Searching Files
      • 4. Users and Groups
        • Working with Users and Groups
        • File and Directory Permissions
        • Changing Users and Passwords
      • 5. Installing Software
        • Package Management
      • 6. Shells
        • Common Command Line Shells
        • Environment Variables & Startup Files
        • Input/Output Redirection
        • Command History & Substitution
      • 7. Utilities and File Editors
        • Searching and Processing Text
        • Networking at the Command Line
        • File Transfer
        • Text Editors and Converters
      • 8. Process Management
        • Process Information
        • Foreground and Background Processes
        • Managing Processes
        • Scheduling Processes
      • 9. Regular Expressions
        • Regular Expressions, Searching, Replacing, Building
      • 10. Bash Scripting
        • Bash Scripting Basics, Control Structures, Loops
      • 🌐Linux101 References
    • TCM - Mobile Application Penetration Testing
      • 1. Introduction & Mobile Pentesting
      • 2. Android Security
      • 3. Android Lab Setup
      • 4. Android Static Analysis
      • 5. Android Dynamic Analysis
      • 6. Android Bug Bounty
      • 7. iOS Security
      • 8. iOS Lab Setup
      • 9. iOS Static Analysis
      • 10. iOS Dynamic Analysis
      • 11. iOS Bug Bounty
      • 🌐MAPT References
    • TCM - Practical Ethical Hacking
      • 1. Introduction & Networking
      • 2. Lab Set Up, Linux & Python
        • Intro to Kali Linux
        • Intro to Python
      • 3. The Ethical Hacker Methodology
        • Information Gathering
        • Scanning & Enumeration
        • Vulnerability Scanning with Nessus
        • Exploitation Basics
        • Capstone Practical Labs
      • 4. Active Directory
        • Active Directory Lab
        • AD - Initial Attack Vectors
        • AD - Post-Compromise Enumeration
        • AD - Post-Compromise Attacks
        • AD - Additional Attacks
        • AD - Case Studies
      • 5. Post Exploitation
      • 6. Web Application
        • Web App Lab Setup
        • Web App - SQL Injection
        • Web App - XSS
        • Web App - Command Injection
        • Web App - Insecure File Upload
        • Web App - Authentication Attacks
        • Web App - XXE
        • Web App - IDOR
        • Web App - Capstone Practical Lab
      • 7. Wireless Attacks
      • 8. Legal Documentation & Report Writing
      • 🌐PEH References
  • 🏠syselement's Blog Home
Powered by GitBook
On this page
  • Environment Variables
  • printenv
  • Global
  • export / unset
  • Local
  • Startup files

Was this helpful?

Edit on GitHub
  1. Courses
  2. TCM - Linux 101
  3. 6. Shells

Environment Variables & Startup Files

PreviousCommon Command Line ShellsNextInput/Output Redirection

Last updated 2 years ago

Was this helpful?

Environment Variables

  • The shell stores information in the environment variables.

  • Each shell has its own values for these variables.

printenv

printenv
# Prints name and value pairs for all the environment variables
# VARIABLE_NAME=VALUE

printenv | grep PATH
  • SHELL - user's shell is bash

  • PWD - current working directory

  • HOME - home directory for the current user

  • PATH - list of the directories searched in order, to find commands to be executed.

    • Current working directory can be put first in this path, easier to execute current working directory programs but can be used for attacks.

There are two types of environment variables: global and local.

Global

  • Global variables can be accessed by anything executed in that shell = Environment Variables

export / unset

# Create a global variable
export COUNT_GLOBAL=33
echo $COUNT_GLOBAL
	33

# Unset a variable
unset COUNT_GLOBAL

Local

  • Local variables are valid only for the current shell (and not for sub-shells) = Shell Variables

# Create a shell variable
COUNT_LOCAL=42
echo $COUNT_LOCAL
	42
# $ is used to tell the shell that it is a variable

# Change shell (create sub-shell) and check the variable doesn't exist
bash
echo $COUNT_LOCAL

Startup files

  • When starting a new bash shell, the shell is configured using startup files.

  • Interactive non-login shell - the type of shell opened by the Terminal

nano .bashrc
# There are various configurations for the shell and commands aliases
# Aliases can be added at the bottom of this file
  • alias name='COMMAND_VALUE' - the alias uses the entire command enclosed in single quotes

  • After adding an alias, a new shell must be created to make the alias work, or use the source .bashrc command in the same shell.

source .bashrc
# Re-runs all the commands in the .bashrc file in the current shell
  • Using a shell other than bash, the startup file name will be different.