SDG
SDG

Reputation: 2342

How do I temporarily change directory and assign a variable a value

(cd /home/sharan/code/darknet; darknet_result=$(git remote -v | grep $SD_Darknet))
echo $darknet_result

The result for $daknet_result is just an empty space . How would I get the varaible to be assigned.

Upvotes: 0

Views: 44

Answers (1)

melpomene
melpomene

Reputation: 85757

darknet_result=$(cd /home/sharan/code/darknet; git remote -v | grep "$SD_Darknet")

The problem in your code is that ( ) starts a new subshell, so any variable assignments there are not visible in the parent shell.

Upvotes: 2

Related Questions