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
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!