Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
100 user(s) are online (70 user(s) are browsing Forums)

Members: 0
Guests: 100

more...

Headlines

 
  Register To Post  

String defines with spaces (shell prob?)
Amigans Defender
Amigans Defender


See User information
Consider this code:
Quote:
#include <stdio.h>

int main(void)
{
printf(PRINTSTRING);
return 0;
}


How do I define PRINTSTRING to something containing a space, through the command line?

This is the generally accepted method:
gcc -o test test.c -DPRINTSTRING=""test 2""
or this:
gcc -o test test.c -DPRINTSTRING='"test 2"'

Neither work with our Shell (I've tried *" as well). What is the correct method?

Go to top
Re: String defines with spaces (shell prob?)
Just popping in
Just popping in


See User information
gcc -o test test.c -DPRINTSTRING="test\ 2"

Appears to have the desired effect on the amiga shell. (I'm not really that familar with quoting rules in amiga shell, and worked that out by experimenatation)

In /bin/sh, you might do:

gcc -o test test.c -DPRINTSTRING=""test 2""

(EDIT: It seems this forum software has a bug. I had to double backslash here to get the right text in the post!)

In this case, the outter backslashed double quote prevents the shell from splitting the content across two arguments and the inner quote satisfies the C source.

I actually prefer the amiga shell rules here, but it fails under /bin/sh because the quoting causes the baskslashed space to be a litteral backslash followed by a space, thus splitting the argument.

Clearly quoting and escaping rules are for massocists.

Lawrence

Go to top
Re: String defines with spaces (shell prob?)
Amigans Defender
Amigans Defender


See User information
Yes, the backslash-space thing works! Thanks!

The weird thing is, I'm using this via a makefile and gmake, which I thought was supposed to spawn sh for each command. Clearly it doesn't. A combination of \""\\ "\" is working, even if it does look ridiculous (not sure if the \" are strictly necessary but they're not harming anything so I'm happy to leave them in)

I hadn't noticed my backslashes had been stripped out of my initial post, I did type them, honest!

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2023 The XOOPS Project