Ok in my bash script i have 5 options to create a simple html script. I need to create a temporary file and whatever the user types will be stored in that file using html codes. And then I have another option in which that temporary file will be moved to the public_html directory in which the user gets to name the file like WEB.html.
Im not really sure how to create a temporary file and then move everything from the temporary file to a file.
This is what i have so far
create temp file
htmlcode=$(mktemp ~/tmp/htmlcode.XXXXXXXXXX)
ls > $htmlcode
and this is what i use to move the users input to the temporary file
echo "$text" >> ~/tmp/htmlcode.XXXXXXXXXX
but when i do this its creating a temp file and a file called htmlcode. It doesnt store in the temp file only in htmlcode?
Again, I don't know what your script looks like, so can't tell what is happening, so from the shell only and it works (I did an echo statement to the temp file and was able to cat the contents):
sherlock ~]$ WEB=$(mktemp -t WEB.XXXXXXXXX)
sherlock ~]$ echo "this is a test" >>$WEB
sherlock ~]$ cat $WEB
this is a test
sherlock ~]$ echo $WEB
/tmp/WEB.uIDFlfw6e
The issue is that you're creating a new (differently named) temp file every time through the while loop - you're echoing to one file and then catting a different file.
You need to check if it already exists, or create the temp file outside the loop (as in dude2cool's answer).
As demonstrated, where you think the problem may be is not always where it actually is :p.