I am super new to shell scripting and I am trying to write the contents of my string variable to file. When I echo the variable before using it to write into the file, it works well. But when the script is completed, there is no update to the file.
My code is:
echo $str
touch $HOME/Documents/config.txt
sudo chmod u+w $HOME/Documents/config.txt
echo "$str" >> sudo $HOME/Documents/config.txt
sudo cp sudo $HOME/Documents/config.txt $HOME/.ssh/
echo $str
echo "configuration file updated!"
I have tried giving it write permission, different ways of writing to the file. Also earlier I thought, .ssh folder is the source of my problem so as you can see, I am first trying to write the file somewhere else and then trying to move it to the .ssh folder. But wherever I try to rite it, file is still empty at the end.