I'm trying to create an auto-compiling script that will compile programs from source, whenever I boot up my computer. It currently goes roughly like this (I can't remember the exact syntax): VAR=$(sudo git pull)if (VAR = Nothing to update){#do nothing}else {#compile package}Will this work?I'm wondering whether sudo git pull is called during VAR=$ or the if statement.
How does the shell script variable, that holds a command, work?
bash;shell script
The command is only called during the initial command substitution, i.e. VAR=$(sudo git pull).You can easily test this.$ VAR=$(touch foo; echo bar)$ echo $VARbar$ ls -l foo-rw-r--r-- 1 me me 0 Dec  7 16:28 fooYou can see that I've created a file foo, and the output of the command substitution (bar) has been assigned to $VAR.Now wait a minute and access the variable again.$ echo $VARbar$ ls -l foo-rw-r--r-- 1 me me 0 Dec  7 16:28 fooYou can see that the modification time of foo has not changed.