-
Notifications
You must be signed in to change notification settings - Fork 337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use sed instead of lua #42
Comments
The justification is that Lua is always present on Debian and is easier to read (although I use sed in all my scripts, but I'm old skool) |
I'm not sure the SEd-functions does the same as the Lua-functions. I don't know Lua. I think the Lua-functions are better now because they seem to uncomment a commented key-value pair. With these suggested functions with SEd the commented key-value pairs would remain commented and the key-value pairs are inserted at the end of the file. This leads to a more difficult-to-read configuration file, where the documentation in comments is in one place and the key-value pair in another. One could replace the Lua-functions with more complex Sed- or AWK-functions. I think this should be done because one should not require that Lua is installed. Also, Lua is not that easy to understand, e.g. what does "^#?%s*" mean? BTW I found this useful discussion: http://stackoverflow.com/questions/2464760/modify-config-file-using-bash-script |
Having said all that I use the following style in my Pi scripts setConfigOption() {
CONFIG_FILE=/boot/config.txt
if grep "$1=" $CONFIG_FILE ; then
sudo sed --in-place -re "s/^#?$1=.+$/$1=$2 #$UPDATE_LABEL/" $CONFIG_FILE
else
echo $1=$2' #'$UPDATE_LABEL| sudo tee -a $CONFIG_FILE
fi
} |
sed -i "s/^# $1/$1/" $CONFIG_FILE
I prefer to have a short one: function set_config_var() {
grep -q "^$1=" $3 && sed -i "/^$1=/c $1=$2" $3 || echo "$1=$2" >> $3
return 0 # search $1 and change "$1=*" to "$1=$2" or append "$1=$2" to EOF
}
set_config_var('cpu_freq', 1000, /boot/config.txt) |
Hi, I doesn't know what does these
lua
means but I think I can replace it with something else which is shorter and reduce the dependencies.I think that function is to change
arm_freq=700
toarm_freq=900
. You can usesed
in that way too:And for the function to get the config values you can do it with
sed
too:With
sed
:Sorry that I didn't send you a pull request as I don't think I should fork it just for these code. I hope you can reduce the dependencies and shorten the code by using a shorter function. Thanks.
Ivan Tham [email protected]
The text was updated successfully, but these errors were encountered: