BCA / B.Tech 9 min read

Variables & File Name Expansion in Linux

Variables & File Name Expansion in Linux:


When using shell scripting in Linux, variables and file name expansion play very important roles. Variables help us store and manage data, while file name expansion gives us the ability to find and manage files in a directory.

Variables in Linux:

Variables are used to store a value in a script or shell. This value can be input from a user, a system value, or a value generated during the execution of a program.
Declaring and Using Variables: In Linux shell scripting, variables are created directly without any keyword (`variable_name=value`). They are accessed using the `$` symbol (e.g., `echo $variable_name`).
Types of Variables: There are two main types: Local Variables (valid only within the current script or shell) and Environment Variables (available to all shells and scripts system-wide, created with `export`).
Arithmetic Operations: Mathematical operations on variables can be performed using the `expr` command or `$((expression))` syntax.

File Name Expansion in Linux:


File name expansion in Linux is used to easily manage files and directories without typing their full names. This is also known as "globbing." Using shell globbing, we can select multiple files based on a pattern.
Wildcards: Special characters used for pattern-matching.
  • * (Asterisk): Represents any number of characters (e.g., `ls *.txt` lists all `.txt` files).
  • ? (Question Mark): Represents a single character (e.g., `ls file?.txt` matches `file1.txt`, `file2.txt`).
  • [] (Square Brackets): Represents a range or a set of options (e.g., `ls file[1-3].txt` matches `file1.txt`, `file2.txt`, `file3.txt`).
Brace Expansion: Used to perform actions on multiple files or directories in a single command (e.g., `mkdir project_{A,B,C}` creates `project_A`, `project_B`, and `project_C`).
Tilde Expansion: The tilde (~) is used to refer to the user's home directory (e.g., `cd ~`).

In this Chapter

Variables & File Name Expansion in Linux
Distributed System in Operating System
Real-Time System in Operating System
System Calls in Operating System
System Programs in Operating System
Structure of an Operating System
Layered Design of an Operating System Structure
UNIX in Operating System
Virtual Machine in Operating System
Kernel-Based Operating System
Process Concept in Operating System
Interacting Processes in Operating System
Threads in Operating System
Fundamentals of Scheduling in Operating System
Scheduling Criteria in Operating System
Long, Medium, and Short-Term Scheduling
Scheduling Algorithms in Operating System
Structure of a Concurrent System
Critical Region in Operating System
Critical Section in Operating System
Inter-process Communication (IPC) in Operating System
Monitors in Operating System
Semaphores in Operating System
Semaphore Implementation & Uses in Operating System
Logical and Physical Address in Operating System
Swapping in Operating System
Contiguous Allocation in Operating System
Segmentation in Operating System
Paging in Operating System
Virtual Memory using Segmentation in Operating System
Interprocess Communication Protocol in Operating System
Network Operating System
Design Issues in Distributed File System
Network Structure in Operating System
Structure of a Distributed System
File System and Coordination in Operating System
History of Linux in Operating System
Linux Commands
Programmer Interface & File Manipulation in Linux
Process Control in Linux
Kernel & Signals in Linux
File System in Linux
Blocks and Inodes in Linux
System Editors in Linux
Character Transliteration in Linux
The `ed` Line Editor in Linux
The `vi` Editor and Its Commands
Shell Scripting in Linux
Looping & Decision Making in Linux Shell Scripting
Arrays in Linux Shell Scripting
Subprograms (Functions) in Linux Shell Scripting
C Interface with Linux
Simple Shell Programs in Linux
BCA Part-1 | Operating Systems | Semester-I | MDSU Exam Paper 2023 (Held in 2024)
What is an Operating System (OS)
Operating System (OS) All Important Questions and Answers in English (MDSU)
BCA || Operating System 2025 Paper || MDSU Exam Paper
BCA | OS(Operating System) 2023 Paper | MDSU Exam Paper
Types of Operating Systems
Goals of an Operating System
Operations of an Operating System
Resource Allocation & Functions in an Operating System
Classes of Operating System
Batch Processing in Operating System
Multiprocessing in Operating System
Time-Sharing in Operating System