How Do I Store The Output of a Command in a Variable in a Bash Script?

  • Read
  • Discuss

You can store the output of a command in a variable in a bash script by using command substitution, which is done using the syntax:

variable=$(command)

For example, to store the output of the ls command in a variable named files, you can use:

files=$(ls)

Then you can access the output of the ls command by using the variable $files.

Leave a Reply

Scroll to Top