Live data from Hacker News

Batsh – A language that compiles to Bash and Windows Batch

batsh.org

81–90 of 130 posts

Re: Batsh – A language that compiles to Bash and Windows Batch

#84
post #68

Earlier quoted context omitted.

My initial thought after seeing this is Windows support is interesting, but the real value is in making bash friendlier. Something that brings syntactic sugar to bash is welcome in my mind, as I always find myself putzing with Google to find solutions to even slightly non-trivial scripts. Perhaps I should just master bash scripting once and for all (I know it's not that complex), but I generally find it unpleasant to…

Use Python? Most of the time I find myself struggling with Bash, it's because a simple script has kept expanding in scope and I'm well into the sunk-cost fallacy in trying to fix "just that one last thing". But unless you have a really specific environment, I'm pretty sure most modern servers probably have Python or Ruby or some other stack that can be a shell script available. If you're in Bash, it's because you wer…

General rule of thumb for me is if it exceeds 100 lines of Bash, it should probably be a Ruby or Python script.

Re: Batsh – A language that compiles to Bash and Windows Batch

#85
post #70

Long ago I thought about writing something that compiles to batch files, if only to make complex logic a bit easier to write or make the process of thinking about every little syntactic idiosyncrasy less tedious. Since then I found PowerShell though, and the need of writing complex and sophisticated batch files isn't so much there anymore¹. Nice to see this compiler adopting some idioms that make it easier for workin…

The main issue with powershell is portability - no guarantee that someone's Windows box will have it installed or not.

I recently wrote a batch script just to make sure it'd run on any Windows system rather than risk powershell. If it was always going to run in a controlled environment, I'd have written it in cygwin bash anyway.

Re: Batsh – A language that compiles to Bash and Windows Batch

#86
post #70

Long ago I thought about writing something that compiles to batch files, if only to make complex logic a bit easier to write or make the process of thinking about every little syntactic idiosyncrasy less tedious. Since then I found PowerShell though, and the need of writing complex and sophisticated batch files isn't so much there anymore¹. Nice to see this compiler adopting some idioms that make it easier for workin…

The main issue with powershell is portability - no guarantee that someone's Windows box will have it installed or not. I recently wrote a batch script just to make sure it'd run on any Windows system rather than risk powershell. If it was always going to run in a controlled environment, I'd have written it in cygwin bash anyway.

You have that guarantee starting with Windows 7. Version is one thing; some nice things are available only in v3+, but v2 is very usable already. Execution policy is another matter, but you can always supply a batch file with the PowerShell script containing

     powershell -ExecutionPolicy Bypass -NoProfile -File %~dp0.ps1 %*
That's what I usually do, which is also helpful for colleagues who have no idea how to run a PowerShell script because just double-clicking it doesn't work.

Often I start with a batch file, just to notice after a dozen lines that this sort of thing is much easier to write and maintain in another language. And in the last two years I shifted more to PowerShell than batch in many cases. Some of that is surely due to atrocities like Windows XP dying out and Vista never being common. For scripts that developers execute on their machines PowerShell should be a fairly safe bet in a Windows environment by now. Deployment or build scripts should probably be MSBuild or something similar.

Re: Batsh – A language that compiles to Bash and Windows Batch

#89

1. From UNIX point-of-view, not all has the luxury of bash, so seems to be quite limited to a certain modern platform? I found out ksh are more prevalent 2. I actually use UnxUtils in windows so I can has POSIX command option (and scripting). Performance-wise, never tested as not needed, all short command / simple script

What systems do you work on where bash isn't around, but ksh is?

If you're referring to Linux as "certain modern platform", I was using bash on Solaris 1.x 20+ years ago. (Granted, back then I had to compile it myself which may not be an option for many.)

Post reply on HN