If you are wondering what $$ (double-dollar) is in a bash shell script, well it is a special variable that can be used to know the Process ID or PID of the current shell.
Let's try running this on a bash shell.
bash_script.sh#!/bin/bash
echo "The process ID of the current shell is: $$"
Result:
./bash_script.sh
The process ID of the current shell is: 4181
List of Special Variable that starts with $ and their meaning
Character | Description |
---|---|
$ | Variable expansion |
$! | Process ID of the most recent background command |
$$ | Process ID of the current shell |
$? | Exit status of the most recently executed command |
$# | Number of command-line arguments passed to the script |
$* | All command-line arguments as a single string (positional parameters) |
$@ | All command-line arguments as separate strings (positional parameters) |
$0 | Name of the script itself (or the shell) |
$1 , $2 , $3 , ... | Individual command-line arguments (positional parameters) |

-
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Bash,
- Bash Hello World! Script Tutorial
- How to run bash command in background
- How to create new user account in Windows bash
- How to Compare Strings in Bash
- Bash: Allow Command to Fail without exiting Script
- Fix bash: script.sh: Permission denied Error
- Bash getopts Command Example
- How to fix bash ping command not found error
- How to add NewLine Character in Bash Script String
- How to Echo Bash Command to a File
- Bash Command to Find String in a File
- How to open new Terminal using Bash Command
- Bash How to Save Output of a Command to a Variable
- Download a SSL Certificate from a URL in Terminal
- Bash Command to Check IP Address
- Know Bash shell version command
- Bash Command To Check If File Exists
- How to run a Command in Bash Script
- How to Compare two Files in Bash Shell
- How to check if a variable is set in Bash Script or Not
- Convert String from uppercase to lowercase in Bash
- How to see Created Accessed Modified and Changed dates of a file using bash terminal command
- Bash Command To Get Current Time
- Bash command to List Files
- Fix: bash: syntax error near unexpected token
More Posts:
- ModuleNotFoundError: No module named qdarkstyle.colorsystem [Python] - Python
- How to Convert a Notepad++ file to an Excel File - NotepadPlusPlus
- What is Carbon Lang (successor to C++?) experimental Language by Google - News
- ZSH: exec format error eclipse M1/M2 Mac - zsh
- How to Rename Docker Image with none TAG and REPOSITORY? - Docker
- How to Display Analog Clock on Mac Menu Bar - MacOS
- Ubuntu Linux: How to Login as root User - Ubuntu
- How to force re-download Gradle Dependencies - Gradle