Bash: saving settings to file
This is a wiki page. Be bold and improve it!
If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.
#!/bin/bash
# Create variable
VERSION=1
# Save variable to file:
echo 'VERSION="'"$VERSION"'"' >> .variables
# Source file to load variables:
. .variable
echo "$VERSION"
# Increment:
let VERSION="$VERSION + 1"
echo "$VERSION"
# Delete previous value from file:
sed --in-place '/^VERSION=/d' ./.variables
# Save new value:
echo 'VERSION="'"$VERSION"'"' >> .variables
# Note that the above, simple implementation will append a new line to .variables each time the value is saved. $VERSION will still evaluate to the last value saved, though.