Live data from Hacker News

Batsh – A language that compiles to Bash and Windows Batch

batsh.org

91–100 of 130 posts

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

#91
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.

Powershell is available on every Server install since 2008 R2. At this point it can be considered standard on every non-ancient Windows box, similar to assuming bash vs sh for example.

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

#92
post #22

This is great for me. As part of my day job I am often stuck writing batch scripts (yes, in 2014) for clients that refuse to run powershell. Writing a simple batch script is usually not a problem, but it can be very encumbering as the complexity increases. Thank you for sharing.

I want to agree, but my major gripe using the different incantantions of Powershell (and I have tried, I am Winboxen admin often in my job and tried it before any other co-worker on Vista, obviously the story has improved since) and the startup time and performance was abysmal. In terms of performance for very basic scripts (silent software installs, 5-10 lines, registry patching, etc.), I see the performance chart a…

The speed difference between PS and cmd.exe is not nearly large enough to justify the incredible hoops you have to jump through to get anything reasonable done in batch. Yes it takes slightly longer to start up, but it has things like native arrays, hashmaps, foreach loops, etc built in to the language! Versus a spaghetti mess of gotos in batch.

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

#93
That files() function will not work properly. I have an old abandoned project, that has a proper directory listing function for batch, you can take that.

http://sourceforge.net/projects/scriptconvert/

Much of the stuff there is half assed but there is some goodies. Like substring searching and dumping of stdout without using temporary files, which is insanely weird in batch definitely take a look.

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

#97
post #86

Earlier quoted context omitted.

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 Pow…

I thought powershell had to be explicitly installed/enabled even in win7.

I'm not going to walk a user through that when I can do what I want in batch (with more pain, but still less than ending up providing support...).

My normal area is Linux though, and both powershell and batch make me appreciate bash so much more. Even those little things like being able to format arbitrary dates as you want...

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

#98
post #86

Earlier quoted context omitted.

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 Pow…

I thought powershell had to be explicitly installed/enabled even in win7. I'm not going to walk a user through that when I can do what I want in batch (with more pain, but still less than ending up providing support...). My normal area is Linux though, and both powershell and batch make me appreciate bash so much more. Even those little things like being able to format arbitrary dates as you want...

You thought wrong. It's installed and enabled by default.

> Even those little things like being able to format arbitrary dates as you want...

You mean like

    $someDate.ToString('yyyy-MM-dd')
    'Today: {0:yyyy-MM-dd}' -f (Get-Date)
    Get-Date -Format yyyy-MM-dd
    date -f yyyy-MM-dd
Right, that's excruciatingly hard in PowerShell (hey, you even get Unix date format strings with Get-Date -UFormat). (But I guess we just come from different worlds here, as every time I have to read or write bash scripts it makes me appreciate PowerShell so much more.) Granted, the batch variant is ... not as pretty:

    for /f "skip=1" %%x in ('wmic os get localdatetime') do if not defined MyDate set MyDate=%%x
    echo Today: %MyDate:~0,4%-%MyDate:~4,2%-%MyDate:~6,2%
And I found the PowerShell script alongside with the batch file a pretty workable solution. Nicer language and still something for clueless users to double-click.

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

#100
post #66
post #63

Earlier quoted context omitted.

One of the reasons I'm still afraid to use Powershell - its just not succint enough for normal day to day operations.

Like all software it will be read far more often than it is written. It is optimised for that common use case.

Not my experience with batch files / shell scripts, but that's hardly any evidence.
Post reply on HN