At times when writing a bash script you want to want to save the output of a command to a variable, in such case, you can use the following syntax.
Example 1: $() Syntax:
#!/bin/bash
whoami_variable=$(whoami)
echo $whoami_variable

Example 2: `` Syntax:
#!/bin/bash
whoami_variable=`whoami`
echo $whoami_variable
-
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:
- [Fixed] Git Clone git@github.com: Permission denied (publickey) Could not read from remote repository Fatal error - Git
- Syntax error, parameterized types are only available if source level is 1.5 or greater [Java] - Eclipse
- How to open a new tab in Notepad++ - NotepadPlusPlus
- Convert GMT/UTC timezone in Excel to EST, CST, MST, PST, AST and HST - Microsoft
- [Solution] macOS could not be installed on your computer OSInstall.mpkg appears to be missing or damaged - MacOS
- Merge multiple zip files without unzipping (extracting) - HowTos
- Only Chessboard using HTML and CSS Code Example - CSS
- How to switch to Powershell on Mac Terminal - Powershell