m4 as script interpreter


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers m4 as script interpreter
# 1  
Old 05-30-2009
m4 problem

#!/usr/bin/m4

when running m4 scripts with "#!/usr/bin/m4" they are executed properly, but "#!/usr/bin/m4" is printed out - how to avoid it?
Thanks in advance.

Last edited by Action; 05-30-2009 at 01:17 PM..
# 2  
Old 05-31-2009
Humm that does not make much sense. How are you invoking the m4 script?
# 3  
Old 05-31-2009
Code:
ed test.m4
test.m4: No such file or directory
a
#!/usr/bin/m4
define(`A',`Turbo')dnl
A
.
w
39
q
chmod a+x test.m4
test.m4
#!/usr/bin/m4
Turbo


Last edited by Action; 05-31-2009 at 10:47 PM.. Reason: post code as code
# 4  
Old 05-31-2009
Hi.

Quote:
Comments in `m4' are normally delimited by the characters `#' and
newline. All characters between the comment delimiters are ignored,
but the entire comment (including the delimiters) is passed through to
the output--comments are _not_ discarded by `m4'.

-- excerpt from info m4
So a code like:
Code:
#!/usr/bin/m4
# This is *another* comment.
define(`A',`Turbo')dnl
A

would produce:
Code:
% ./s1
#!/usr/bin/m4
# This is *another* comment.
Turbo

You could avoid this with:
Code:
#!/usr/bin/env bash

m4 <<EOF
define('A','Turbo')dnl
A
EOF

which produces:
Code:
% ./s2
A

NOTE: see correction for quoting in post below.

Best wishes ... cheers, drl

Last edited by drl; 06-03-2009 at 12:07 AM.. Reason: Add note for correction in later post.
# 5  
Old 05-31-2009
Quote:
Originally Posted by drl
Hi.


So a code like:
Code:
#!/usr/bin/m4
# This is *another* comment.
define(`A',`Turbo')dnl
A

would produce:
Code:
% ./s1
#!/usr/bin/m4
# This is *another* comment.
Turbo

You could avoid this with:
Code:
#!/usr/bin/env bash

m4 <<EOF
define('A','Turbo')dnl
A
EOF

which produces:
Code:
% ./s2
A

Best wishes ... cheers, drl
Thank you!
# 6  
Old 06-03-2009
Hi.

Correction for quoting:
Code:
#!/usr/bin/env bash

m4 <<'EOF'
define(`A',`Turbo')dnl
A
EOF

producing:
Code:
% ./s2
Turbo

Apologies for the confusion ... cheers, drl
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Linux

interpreter files

Can you explain me what is ment by interpreter files ?? Why and how they are used?? (1 Reply)
Discussion started by: kkalyan
1 Replies

2. Shell Programming and Scripting

Bad Interpreter

Hi. My name is Caleb (a.k.a RagingNinja) form the whited00r forums. (Whited00r makes custom firmware for iOS devices). I have been learning and creating simple shells scripts. I have been recently using VIM for Windows or using VirtualBox to run the UBUNTU OS within VirtualBox to create my shell... (2 Replies)
Discussion started by: RagingNinja
2 Replies

3. Shell Programming and Scripting

bad interpreter when running script

Hi All, I'm not confortable in writing script, can someone can help me, when I run that script below i found this error code : -bash: ./script.sh: /bin/sh.: bad interpreter: Here is the script for i in * x=${i##*.} z=$(perl -e 'print time;') t=$(echo $z-$x|bc)... (12 Replies)
Discussion started by: bzb23
12 Replies

4. Programming

Java Interpreter

Hello guys - do you have any sample program implementing UNIX commands in an interpreter with Java? I can look up the simple ones such "ls" etc and then write my own commands. I would appreciate it. (2 Replies)
Discussion started by: cmontr
2 Replies

5. Shell Programming and Scripting

Executing expect script giving message as bad interpreter: Permission denied

Hi Gurus, I am new to scripting and needs your help in expect script used for telnet. I wrote a simple script as #!/usr/bin/expect-5.43 -f spawn telnet localhost 2233 expect "password:" send "secret\r" send "i data.cnbc.com\r" send "exit\r" expect eof When I am trying to execute... (2 Replies)
Discussion started by: niks_yv
2 Replies

6. Shell Programming and Scripting

Test for shell interpreter at beginning of script

What would be the best way or method to determine or test for the shell interpreter at the beginning of a script in the event one shell is not available? If I use the following: #!/bin/bash and /bin/bash is not available, then use I'd like to use /bin/ksh if it is available. #!/bin/ksh (8 Replies)
Discussion started by: nck
8 Replies

7. UNIX for Dummies Questions & Answers

an command interpreter

if somebody can help me pls. i need the source code for a shell which compiles C or java programs. i need a very short and simple one, just for the compiling part, in UNIX Respect (4 Replies)
Discussion started by: zlatan005
4 Replies

8. Programming

When I am writing my own interpreter...

While trying out my hand at writing an interpreter, I was wondering about a a few issues one of which is the following: When I run a command such as jobs in the shell, I get a list of all the background jobs that are running... But if I need my interpreter to run that command, how would I be doing... (34 Replies)
Discussion started by: Legend986
34 Replies

9. Shell Programming and Scripting

#!/usr/bin/ksh Command Interpreter in a sh script

Hi, I have a developer that is trying to start a script with sh "scriptname". In the script, he is specifying #!/usr/bin/ksh as the command interpreter. For some reason sh is ignoring the #!/usr/bin/ksh. We are running Solaris 8. Does anyone have any ideas what could be causing this? Here... (3 Replies)
Discussion started by: ckeith79
3 Replies
Login or Register to Ask a Question