D for scripting?

岩倉 澪 via Digitalmars-d digitalmars-d at puremagic.com
Thu Jan 19 19:59:12 PST 2017


Last weekend I tried porting some old shell scripts to D, as I 
think D is actually extremely well suited as a shell script 
replacement. My scripts are so much more robust now and do things 
like rolling back on errors and having debug mode, all with 
roughly the same amount of lines as the flimsy old shell scripts.

I have two points of feedback regarding rdmd:

* If you name your script without a .d extension, rdmd fails 
saying the module is in script.d which cannot be read
* rdmd doesn't seem to play nice with symlinks

I keep my scripts in ~/scripts so that I can just pull them from 
github and go on my merry way, with symlinks in /usr/local/bin, 
but rdmd doesn't -I the real directory, it does -I/usr/local/bin, 
and if I symlink a script.d as /usr/local/bin/script, it can't 
find the module.
I can pass -I/home/mio/scripts on the shebang line at least...

Furthermore, if I -J a folder with string imports I would have to 
type out the fully qualified path just like with -I. It would be 
so much more convenient if rdmd would follow the symlink to the 
scripts directory, change the working directory, and then 
compile, or something like that.

Is anyone else using D for scripting?
I feel like the shebang is totally worth it if I could name my 
file without .d and symlink to it. Would it be reasonable to 
change rdmd to allow these features? I'd be happy to look into 
writing a patch for it if it wouldn't be a waste of time.


More information about the Digitalmars-d mailing list