Home » Infrastructure » Unix » How can I create a short file from within a shell script?
How can I create a short file from within a shell script? [message #98058] Mon, 12 January 2004 06:46 Go to next message
Art Metzer
Messages: 2480
Registered: December 2002
Senior Member
Hello,

I'm trying to create a Korn shell script that will create a file by the name of a.txt that in turn contains only the text NO DATA.

Here's the shell script (filemaker.sh) I've been attempting:
cat > a.txt
NO DATA    
^D
Note, to get that Ctrl-D in there, I did do a Ctrl-V in vi, followed by a Ctrl-D.

Now, I go to execute my shell script:
$ chmod +x filemaker.sh
$ filemaker.sh         
 
...and it just hangs there. What's worse, after I Ctrl-C out of the hang, a.txt exists, but is completely empty (0 lines, 0 characters).

How can I create that file with the name and contents I want from within a Korn shell script?

Thanks,

Art.
Re: How can I create a short file from within a shell script? [message #98059 is a reply to message #98058] Mon, 12 January 2004 22:22 Go to previous messageGo to next message
Werner
Messages: 11
Registered: November 1999
Junior Member
Hello Art., may be you can use:
echo "NO DATA" > a.text
echo "^D" >> a.txt

Regards,
Werner
Re: How can I create a short file from within a shell script? [message #98068 is a reply to message #98058] Sun, 18 January 2004 07:54 Go to previous messageGo to next message
William Robertson
Messages: 1643
Registered: August 2003
Location: London, UK
Senior Member
Try:

cat > a.txt<<-ENDCAT
NO DATA    
ENDCAT
Re: How can I create a short file from within a shell script? [message #98102 is a reply to message #98058] Wed, 18 February 2004 10:52 Go to previous message
Sanjay
Messages: 236
Registered: July 2000
Senior Member
So why do you want a ^D in the end ??

I would simply do

echo "NO DATA" > a.text

as mentioned by Werner ...
Previous Topic: passing the database column values to a shell script
Next Topic: FAILED TO INSTALL ORACLE 8i ON UNIXWARE
Goto Forum:
  


Current Time: Tue Apr 16 11:24:37 CDT 2024