Just use shell variable expansion, like this:
password='MYPASSWORD'
uci set wireless.@wifi-iface[0].key="$password"
The important thing here is the dollar sign in $password
: which signals the shell that what you want is not the string password
itself, but the value the variable password
(defined before) points to.
If you want to read password
's value from a file instead of defining it in inline, two approaches are available.
First approach
Create a configuration file (e.g. myscript.conf
) and source
it. E.g., myscript.conf
will contain
password='MYPASSWORD`
and myscript
will contain
source myscript.conf
uci set wireless.@wifi-iface[0].encryption=psk
uci set wireless.@wifi-iface[0].key="$password"
uci commit wireless
wifi
Be aware that this approach might have security flaws (everything you write into myscript.conf
gets actually executed in the shell).
Second approach Create a password file and just read its content. E.g., the password file will look like this
MYPASSWORD
I.e., it will contain just the password. On the other hand, myscript
will be
password=$(cat password_file)
uci set wireless.@wifi-iface[0].encryption=psk
uci set wireless.@wifi-iface[0].key="$password"
uci commit wireless
wifi
Here we read the content of password_file
by using cat
and storing it into the variable password
.