I am writing my own script to install my Arch Linux. I will only have few options to change every time I reinstall the system or use my script in another device. Is there a way I can write the variables at the top of my script? I came across something similar to the below but it doesn't seem to work:
disk="nvme0n1"
locale="en_US.UTF-8"
and then somewhere in the script there will be:
gdisk /dev/$disk
echo 'LANG=$locale' >> /etc/locale.conf
I can then just modify my variables at the top of my script every time I want to change something.
I am a beginner in writing scripts. I am happy if someone can explain another/better way of achieving the above.
echo 'LANG=$locale'or, better,printf '%s\n' "$locale"instead ofecho 'LANG=$locale'because variables are not expanded in single quotes, but apart from that, what is the problem you are facing? How does it "not work"? – terdon Oct 10 '22 at 14:54echoline use double quotes around the string where you want the variable expanded:echo "LANG=$locale" >> /etc/locale.conf– Sotto Voce Oct 10 '22 at 14:56Perhapse, I need to know what are the prerequistes for this to work. Especially when the variable is in the middle of a command like these 2 examples I gave.
– Muzzamil Oct 10 '22 at 16:06echo 'LANG=$locale' >> /etc/locale.confwill fail butecho "LANG=$locale" >> /etc/locale.confwill work. – terdon Oct 10 '22 at 16:39$code=Inputin the title, and that won't work in the shell (it'll expand$codeand run the result as an argument, e.g. withcode=foo,$code=Inputwould try to run a command calledfoo=Input). – ilkkachu Oct 10 '22 at 17:54