How to assign the output of a Bash command to a variable? [duplicate]

I have a problem putting the content of pwd command into a shell variable that I’ll use later.

Here is my shell code (the loop doesn’t stop):

#!/bin/bash
pwd= `pwd`
until [ $pwd = "https://stackoverflow.com/" ]
    do
        echo $pwd
        ls && cd .. && ls 
        $pwd= `pwd` 
    done

Could you spot my mistake, please?

5 Answers
5

Leave a Comment