News for hackers. Stuff that matters.
Re:Amber – the programming language compiled to Bash by liampulles on Wednesday May 22, 2024 @03:40AM (#40438323)
What I really want for scripting usecases is a language that has modern language concepts (easy to use arrays and maps, text formatting strings, etc) but that allows me to call commands as easily as I could call functions.

Maybe there are existing scripting langs that make this so? Ambers approach is not bad but I feel it could be even better.

Re:Amber – the programming language compiled to Bash by inbetween on Wednesday May 22, 2024 @04:15AM (#40438564)
Marcel the shell is surprisingly effective for that. It is python with seamless calling of external commands and piping:

    ls /home/jao | map (lambda f: (f, f.size))
https://github.com/geophile/marcel
Re:Amber – the programming language compiled to Bash by coolcoder613 on Wednesday May 22, 2024 @03:57AM (#40438438)
Xonsh maybe?

The syntax is something like this:

  text=@(ls -lh).replace('a','b').split('b')
Re:Amber – the programming language compiled to Bash by mattbessey on Wednesday May 22, 2024 @03:52AM (#40438407)
try ruby. there are several ways to call commands but the simplest is simply the command string in backticks
Re:Amber – the programming language compiled to Bash by cglong on Wednesday May 22, 2024 @07:33AM (#40439728)
Have you taken a look at PowerShell? It can infer whether you're invoking a command or function.

Disclaimer: I work at Microsoft, but not on PowerShell.

Re:Amber – the programming language compiled to Bash by mst on Wednesday May 22, 2024 @08:27AM (#40440129)
It's generally quite doable to write functions for that, e.g. in perl -

  use IPC::System::Simple qw(capture);
  use Sub::Install qw(install_sub);
  
  foreach my $command (qw(foo bar baz)) {
    install_sub $command => sub { capture($command, @_) }
  }
  
  ...
  
  my $output = foo($x, $y); # will throw if calling 'foo $x $y' returns non-zero
(there's a Shell.pm but it's not as helpful with errors; I should probably consider rewriting it a more modern way)

Note that if you're distributing code p3rl.org/App::FatPacker will produce a single fat script that has (pure perl) dependencies included so you don't need to install anything (except for having a perl VM in $PATH).

There's also multiple libraries that provide a '$' function in JS (which may be why amber picked that delimeter) and then you can do

  let output = await $`foo ${x} ${y}`;
(the template string's variable parts get autoquoted)

Note that bun.sh has a 'bun compile' subcommand that bolts together your (pure JS) code and the static bun binary to produce a single file you can also copy around.

I'd suggest avoiding backticks in ... everything. In shell, $() is nicer, and both perl's and ruby's backticks require effort to use safely.

No idea re python but I see no reason you couldn't do the function generation thing if you wanted to, and somebody's probably librarified it already.

Re:Amber – the programming language compiled to Bash by klibertp on Wednesday May 22, 2024 @10:27AM (#40441431)
Rash (https://rash-lang.org/) and Oil (https://www.oilshell.org/release/latest/doc/ysh-tour.html) come to mind. Xonsh, too, as mentioned. Powershell too.

Most high-level languages have packages that implement DSLs for running and connecting subprocesses. Python has both `subprocess` in stdlib and things like plumbum (https://plumbum.readthedocs.io/en/latest/index.html) or fabric as 3rd party packages. Scala has a little DSL ("echo 1" #| "cat" !) for this in stdlib. How lightweight the syntax is depends on how DSL-friendly the language is, so things like Ruby or Raku might be your best bets.

Re:Amber – the programming language compiled to Bash by liampulles on Wednesday May 22, 2024 @12:03PM (#40442578)
Oil/ysh looks very much like what I would like - thanks!