473,698 Members | 2,841 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

want a "here doc" equivalent in "c"

I want to embed a bash script inside the c program.

How could you do the below bash snippet in "c"?:

cat > /tmp/foo <<\__EOD_
all kinds of nasty stuff in here including single and double quotes
and bashslashes ..
(note that the here doc delimiter is preceded by a "\"
__EOD_

--
regards,
Tom Rodman
pls run for my address:
perl -e 'print unpack("u", "1\:6UP\,\$\!T\ <F\]D\;6\%N\+F\-O\;0H\`");'
Nov 13 '05
27 8049
August Derleth wrote:
Richard Heathfield <do******@addre ss.co.uk.invali d> wrote in
news:bj******** **@hercules.bti nternet.com on Thu 04 Sep 2003 06:34:49p:
<snip>
Which FAQ tells them that VisualAda++ is off-topic here? I don't think
the word "topic" is even mentioned in the FAQ. It certainly doesn't
appear in the index of the book version.


http://www.eskimo.com/~scs/C-faq/q19.1.html -- First topic in the section
System Dependencies. It says:

"Since comp.lang.c is oriented towards topics that C does deal with, you
will usually get better answers to these questions by referring to a
system-specific newsgroup such as comp.unix.quest ions or
comp.os.msdos.p rogrammer, and to the FAQ lists for these groups."


I don't suppose I should be too surprised that this sentence doesn't appear
in my paper edition. Clearly, it's been edited out as being irrelevant to
casual purchasers.
It isn't as hardassed as most clc regs are, but it does gently state that
we deal with Standard C, not Ada, not Pascal, not system-specific
extensions to C.
Yes, that's a fair point.
And if we see a post about VisualAda++, we will storm Redmond and shove
the One Boot up the Gates of Hell.
Why wait for a post about VisualAda++? If it feels good, do it.
So was I wrong? Yes, I was. Will I admit that? No, not really. I can still
quote mostly-relevant portions of the FAQ and appeal to the common sense
of Usenetters.


The common sense of Usenetters? You're new here, right? ;-)
--
Richard Heathfield : bi****@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #21
August Derleth wrote:
Richard Heathfield <do******@addre ss.co.uk.invali d> wrote in
news:bj******** **@hercules.bti nternet.com on Thu 04 Sep 2003 03:41:19p:
Alan Balmer wrote:
Some of us prefer the group /not/ to have a charter, not least because
of the Schadenfreude that inevitably results from someone thoughtlessly
suggesting that we refer to it.


And I might write one, just for the Schadenfreude that will result when
someone smugly says that we don't have one.


But since any charter you write would be yours, not ours, the Schadenfreude
would be ours, not yours.

--
Richard Heathfield : bi****@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #22
Pieter Droogendijk wrote:
Tom Rodman <Use-Author-Address-Header@[127.1]> wrote:
I want to embed a bash script inside the c program.


Standard C knows nothing of 'embed', 'bash' or 'script'.
How could you do the below bash snippet in "c"?:

cat > /tmp/foo <<\__EOD_
all kinds of nasty stuff in here including single and
double quotes and bashslashes ..
(note that the here doc delimiter is preceded by a "\"
__EOD_


Ask this in comp.unix.progr ammer and prepare to be helped, or
rephrase the question to something not involving anything
platform-specific.


It is a perfectly valid C question, even though he is describing
the off-topic eventual use. The real question is "how to embed
all those characters within C source code", and the answer is to
use the escape character '\'.

--
Replies should be to the newsgroup
Chuck Falconer, on vacation.
Nov 13 '05 #23
On Fri, 05 Sep 2003 02:51:45 GMT, August Derleth
<li************ *****@onewest.n et> wrote:
Richard Heathfield <do******@addre ss.co.uk.invali d> wrote in
news:bj******* ***@hercules.bt internet.com on Thu 04 Sep 2003 03:41:19p:
Alan Balmer wrote:
Some of us prefer the group /not/ to have a charter, not least because
of the Schadenfreude that inevitably results from someone thoughtlessly
suggesting that we refer to it.
I might wish I had written the above, but it was actually Richard.
And I might write one, just for the Schadenfreude that will result when
someone smugly says that we don't have one.

... grumble grumble grumble ...

--
Al Balmer
Balmer Consulting
re************* ***********@att .net
Nov 13 '05 #24
Pieter Droogendijk wrote:
Tom Rodman <Use-Author-Address-Header@[127.1]> wrote:
I want to embed a bash script inside the c program.


Standard C knows nothing of 'embed', 'bash' or 'script'.
How could you do the below bash snippet in "c"?:

cat > /tmp/foo <<\__EOD_
all kinds of nasty stuff in here including single and
double quotes and bashslashes ..
(note that the here doc delimiter is preceded by a "\"
__EOD_


Ask this in comp.unix.progr ammer and prepare to be helped, or
rephrase the question to something not involving anything
platform-specific.


It is a perfectly valid C question, even though he is describing
the off-topic eventual use. The real question is "how to embed
all those characters within C source code", and the answer is to
use the escape character '\'.

--
Replies should be to the newsgroup
Chuck Falconer, on vacation.
Nov 13 '05 #25
Derk:

Thanks for your help - I'll use your approach; will write a
shell script filter to generate the meta-quoted strings in text[].

--
regards,
Tom Rodman
pls run for my address:
perl -e 'print unpack("u", "1\:6UP\,\$\!T\ <F\]D\;6\%N\+F\-O\;0H\`");'

Derk wrote:
<snip>
char *text[] = {
/*X*/
"line 1\n",
"line 2\n",
...,
"line n\n",
/*Y*/
0
};
<snip>The lines between X and Y have to have quotes and backslashes backslashed escaped,
besides the initial '"' and trailing 'n",' for each line. It's a pain to do this
by hand. It's easy to write a simple filter for this and then do something like
herefilter <textfile >textfile.her e
and replace the /*X*/.../*Y*/ with
#include "textfile.h ere"

I do something similar quite often to insert Tcl scripts into C programs
with the makefile calling the filter and compiling the file.

Nov 13 '05 #26
On Fri, 05 Sep 2003 02:51:45 GMT, August Derleth
<li************ *****@onewest.n et> wrote:
Richard Heathfield <do******@addre ss.co.uk.invali d> wrote in
news:bj******* ***@hercules.bt internet.com on Thu 04 Sep 2003 03:41:19p:
Alan Balmer wrote:
Some of us prefer the group /not/ to have a charter, not least because
of the Schadenfreude that inevitably results from someone thoughtlessly
suggesting that we refer to it.
I might wish I had written the above, but it was actually Richard.
And I might write one, just for the Schadenfreude that will result when
someone smugly says that we don't have one.

... grumble grumble grumble ...

--
Al Balmer
Balmer Consulting
re************* ***********@att .net
Nov 13 '05 #27
Derk:

Thanks for your help - I'll use your approach; will write a
shell script filter to generate the meta-quoted strings in text[].

--
regards,
Tom Rodman
pls run for my address:
perl -e 'print unpack("u", "1\:6UP\,\$\!T\ <F\]D\;6\%N\+F\-O\;0H\`");'

Derk wrote:
<snip>
char *text[] = {
/*X*/
"line 1\n",
"line 2\n",
...,
"line n\n",
/*Y*/
0
};
<snip>The lines between X and Y have to have quotes and backslashes backslashed escaped,
besides the initial '"' and trailing 'n",' for each line. It's a pain to do this
by hand. It's easy to write a simple filter for this and then do something like
herefilter <textfile >textfile.her e
and replace the /*X*/.../*Y*/ with
#include "textfile.h ere"

I do something similar quite often to insert Tcl scripts into C programs
with the makefile calling the filter and compiling the file.

Nov 13 '05 #28

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

33
9164
by: Jim Hill | last post by:
I've done some Googling around on this and it seems like creating a here document is a bit tricky with Python. Trivial via triple-quoted strings if there's no need for variable interpolation but requiring a long, long formatted arglist via (%s,%s,%s,ad infinitum) if there is. So my question is: Is there a way to produce a very long multiline string of output with variables' values inserted without having to resort to this wacky """v...
5
3473
by: karteikarte | last post by:
hi, i just wondered how to retrieve the 4digit key of this script? anybody who can help? best regards Karteikarte <script type="text/javascript"> <!-- Key-code script by Bart Jellema var code=0 var mul=1
3
18258
by: Summit | last post by:
Does anyone know what the C# equivalent for VB6 End is? I'm starting up a form with a boolean test. If I fail, I just want to end the app. Even though I close the form, it picks up on the line after the bracket and continues loading the form. Here's my snippet: DalMan._drCurrentUser = DalMan._dtUsers.FindByUserName("Init"); if (DalMan._drCurrentUser == null)
1
9184
by: gslim | last post by:
I am trying to implement the busybox sample from // From Mark Wagner // http://blogs.crsw.com/mark/articles/642.aspx When I get to this line I get an access denied error. Could someone give me an idea why this might be? Here is the entire function
35
29217
by: erikwickstrom | last post by:
Hi all, I'm sorry about the newbie question, but I've been searching all afternoon and can't find the answer! I'm trying to get this bit of code to work without triggering the IndexError. import shutil, os, sys
206
8324
by: WaterWalk | last post by:
I've just read an article "Building Robust System" by Gerald Jay Sussman. The article is here: http://swiss.csail.mit.edu/classes/symbolic/spring07/readings/robust-systems.pdf In it there is a footprint which says: "Indeed, one often hears arguments against building exibility into an engineered sys- tem. For example, in the philosophy of the computer language Python it is claimed: \There should be one|and preferably only one|obvious...
13
7956
by: xzzy | last post by:
None of the following properly do the VB.net double quote conversion because all of the following in csharp convert to \" instead of just a double quote: " I have tried: char myDoubleQuote = (char)34; string myDoubleQuote = "" + (char)34;
1
3556
by: murthychvrm | last post by:
why we declare "ReportDocument doc;" in this coding?what it is doing here? using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI;
0
1447
by: vhrao | last post by:
I want to Encrypt and Decrypt different elements of xml file with different RSACryptoServiceProvider keys RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider(cspParams); string publicKey = rsaKey.ToXmlString(false); RSACryptoServiceProvider rsaKey2 = new RSACryptoServiceProvider(cspParams2); string publicKey2 = rsaKey2.ToXmlString(false); Here is my data file I want to encrypt: <?xml version="1.0" encoding="utf-8" ?> <root>...
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.