View previous topic :: View next topic |
Author |
Message |
keinfarbton
Joined: 03 Dec 2005 Posts: 224 Location: Stuttgart - Germany
|
Posted: Mon Oct 02, 2006 6:50 am Post subject: #! on linux |
|
|
#! is also called shebang or hashbang.
I tried to use build/bud on linux with the shells #! syntax, but I can't get it to run.
This feature would be very useful on linux, because it would enable D as a scripting language. I fact without build, this is not possible. Dmd supports this feature, but without the ability to automatically build and link the needed files, it is not really useful.
dmd supports #! line in source files since http://www.digitalmars.com/d/changelog.html#new0146.
A more detailed description about #!:
http://homepages.cwi.nl/~aeb/std/hashexclam-1.html#ss1.1. Note the mixing of the argument sequence. So if the -exec argument needs to be the last, there is the need to correct this.
If I add the following line into my source file:
Code: | #!/usr/bin/build303 -full -cleanup -op -exec |
Then I get the error message:
Code: | Error: unrecognized switch '-full -cleanup -op -exec' |
I think this is because the shell passes these arguments as one argument, not as four. |
|
Back to top |
|
|
Derek Parnell
Joined: 22 Apr 2004 Posts: 408 Location: Melbourne, Australia
|
Posted: Mon Oct 02, 2006 11:48 am Post subject: Re: #! on linux |
|
|
keinfarbton wrote: | #! is also called shebang or hashbang.
I tried to use build/bud on linux with the shells #! syntax, but I can't get it to run.
This feature would be very useful on linux |
So programs that support the '#!' must do their own command line parsing. Sort of defeats the purpose of the shell. Anyhow, I was not aware of this restriction. I'll add support for #! to Build.
BTW, the "-exec" does not have to go anywhere in particular. _________________ --
Derek
skype name: derek.j.parnell |
|
Back to top |
|
|
keinfarbton
Joined: 03 Dec 2005 Posts: 224 Location: Stuttgart - Germany
|
Posted: Mon Oct 02, 2006 12:48 pm Post subject: |
|
|
Cool, thx. |
|
Back to top |
|
|
pragma
Joined: 28 May 2004 Posts: 607 Location: Washington, DC
|
Posted: Mon Oct 02, 2006 2:03 pm Post subject: Re: #! on linux |
|
|
Derek Parnell wrote: | keinfarbton wrote: | #! is also called shebang or hashbang.
I tried to use build/bud on linux with the shells #! syntax, but I can't get it to run.
This feature would be very useful on linux |
So programs that support the '#!' must do their own command line parsing. Sort of defeats the purpose of the shell. Anyhow, I was not aware of this restriction. I'll add support for #! to Build.
BTW, the "-exec" does not have to go anywhere in particular. |
Derek, just an idea out of the blue: would it make sense to pass arguments to build via a pragma() instead?
Code: | version(build) pragma(options,"-full -cleanup -op -exec"); |
Or something similar? It's really not so dissimilar than using the shebang line, only this way, it's more flexible. _________________ -- !Eric.t.Anderton at gmail |
|
Back to top |
|
|
keinfarbton
Joined: 03 Dec 2005 Posts: 224 Location: Stuttgart - Germany
|
Posted: Mon Oct 02, 2006 3:12 pm Post subject: |
|
|
I like this idea too.
For a first version - to get some experience with this feature - one could have the user to split the args:
Code: | #!/usr/bin/bud
version(build){
pragma(options,"-full");
pragma(options,"-cleanup");
pragma(options,"-op");
pragma(options,"-exec");
}
.... |
I see only one difficulty. Not related to the pragmas...
It should also be possible to give the user-program args on command line, the caller shall use this like a compiled program.
Code: | frank@linux:~/$ ./mysource.d arg1 arg2=3
|
Now build/bud is called with this arg-list:
Code: | "/usr/bin/bud", "./mysource.d", "arg1" "arg2=3" |
How can build/bud know that this is an argument for the user-program? |
|
Back to top |
|
|
Derek Parnell
Joined: 22 Apr 2004 Posts: 408 Location: Melbourne, Australia
|
Posted: Mon Oct 02, 2006 3:56 pm Post subject: Re: #! on linux |
|
|
pragma wrote: |
Derek, just an idea out of the blue: would it make sense to pass arguments to build via a pragma() instead?
Code: | version(build) pragma(options,"-full -cleanup -op -exec"); |
Or something similar? It's really not so dissimilar than using the shebang line, only this way, it's more flexible. |
This has been on the TODO list for awhile. It's not hard to get the args, but I have to reorganize the structure of the program's logic flow. Currently, it gathers all the switches and arguments, then runs the compiler etc... With this change, I'll have to be able to run the compiler for different sets of 'command line' arguments.
I want to do this but it might not show up until v4.0 _________________ --
Derek
skype name: derek.j.parnell |
|
Back to top |
|
|
Derek Parnell
Joined: 22 Apr 2004 Posts: 408 Location: Melbourne, Australia
|
Posted: Mon Oct 02, 2006 3:59 pm Post subject: |
|
|
keinfarbton wrote: |
I see only one difficulty. Not related to the pragmas...
It should also be possible to give the user-program args on command line, the caller shall use this like a compiled program.
Code: | frank@linux:~/$ ./mysource.d arg1 arg2=3
|
Now build/bud is called with this arg-list:
Code: | "/usr/bin/bud", "./mysource.d", "arg1" "arg2=3" |
How can build/bud know that this is an argument for the user-program? |
Currently you can give the args on the -exec switch, but I see your point. I'll add a new switch "-execargs" with which you can pass arguments to the compiled program when Build runs it via "-exec". _________________ --
Derek
skype name: derek.j.parnell |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|