Hi All,

I am facing a problem. I need to do a script which to generate the temp.txt file first when select from database, until the data finish store into temp file then -> MV temp.txt to finish.txt.

Any idea? or any sample script for me to refer? I am shell script beginner. Thank you

Recommended Answers

Ot create a file and pipe something into it whatever you like you can use the redirect to a file

echo "hello" > /tmp/temp.txt

This will open a new file or overwrite an existing file in the same location and then put the text hello into /tmp/temp.txt. …

Jump to Post

All 3 Replies

Ot create a file and pipe something into it whatever you like you can use the redirect to a file

echo "hello" > /tmp/temp.txt

This will open a new file or overwrite an existing file in the same location and then put the text hello into /tmp/temp.txt. If you want to add addtional lines use the following command

echo "hello chris" >> /tmp/temp.txt

You file will then contain hello followed by hello chris to move this file from one location to the other use the following code

mv location1 location2
e.g
mv /tmp/temp.txt /tmp/finished.txt

oooic... I get what ur means already...
Done liao..
haha..!!
thank you chris5126

Do you use the temporary file for anything in the meantime? I'm biased against temporary files when they can be avoided, personally... Why not stuff it all into a variable and then stuff it into a file when it's done, or just write directly to the destination file? Here's an example of using a variable:

## the quotes are important!
RESULT="$(command --switches)"
echo "$RESULT" > /tmp/finished.txt

Hope that helps!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.