A non-existent file will be created upon redirection, i.e. both the operators > and >> will open a "fresh" file for output. Be aware that >> will append to an existing file.
touch filename will create an empty file independently.
address1="10.0.1.4"
if [ ! -f addrfile.txt ]; then
echo "$address1" > "addrfile.txt"
fi
echo "$address2">"addrfile.txt"
echo "read address from file: "
echo $address2
it creates the file and display only the message read address from file without address2 ! Have you an idea please. (my goal is to store and get a variable in/from a file..
In line 3: you do not need quotes around the file name.
In line 5: address2 is not defined. and again the file name does not need to be in quotes. If address2 had been defined, it would erase the work done by line 3.
In line 7: You should use "cat" to display the contents of a file; "echo" to display the contents of a variable.