Live data from Hacker News

Amber the programming language compiled to Bash/Ksh/Zsh

amber-lang.com

21–30 of 72 posts

Re: Amber the programming language compiled to Bash/Ksh/Zsh

#21
post #19

Any language is a shell script if you're brave enough: https://en.wikipedia.org/wiki/Shebang_%28Unix%29

Exactly #!/usr/bin/tcc -run #include int main(int argc, char **argv) { printf("Hello from C!\n"); for (int i = 1; i And ready is your cscript :) $ chmod u+x cscript && ./cscript hello world Hello from C! argument 1: hello argument 2: world (I can't even articulate why I love it so much that this works)

Can you change the current working directory? If not, it's not a shell script.

Re: Amber the programming language compiled to Bash/Ksh/Zsh

#23

unclear use case imo - this sacrifices the ergonomics of actual bash scripting, and hides it behind another language If your script is complex enough to need a higher level language you might as well just switch to python

bash scripting has ergonomics?

Re: Amber the programming language compiled to Bash/Ksh/Zsh

#25
post #21
post #19

Earlier quoted context omitted.

Exactly #!/usr/bin/tcc -run #include int main(int argc, char **argv) { printf("Hello from C!\n"); for (int i = 1; i And ready is your cscript :) $ chmod u+x cscript && ./cscript hello world Hello from C! argument 1: hello argument 2: world (I can't even articulate why I love it so much that this works)

Can you change the current working directory? If not, it's not a shell script.

Obviously it's not a shell script, it's still C. It's fun though and being able to freely specify an interpreter/execution path using a shebang has led me to write some useful little command line utilities in unlikely programming languages over the years. That said, not sure why changing the working directory would be the litmus test. A C program can change its own working directory just as easily as an ordinarily executed bash script?

  $ cat bscript.sh && echo "---" && ./bscript.sh 
  #!/usr/bin/bash
  cd testdir/
  ls
  ---
  dummyfile
in C you can change dir easily via `chdir()`[1]

  $ cat cscript && echo "---" && ./cscript 
  #!/usr/bin/tcc -run
    
  #include 
  #include 
  #include 
    
  int main(void)
  {
      if (chdir("testdir") == -1) {
          perror("chdir");
          return EXIT_FAILURE;
      }
    
      execlp("ls", "ls", (char *)NULL);
      perror("execlp");
      return EXIT_FAILURE;
  }
  ---
  dummyfile
[1] https://www.man7.org/linux/man-pages/man2/chdir.2.html

If you meant somehow changing the parent shell's directory an ordinary bash script doesn't do that either

Re: Amber the programming language compiled to Bash/Ksh/Zsh

#26
post #21
post #19

Earlier quoted context omitted.

Exactly #!/usr/bin/tcc -run #include int main(int argc, char **argv) { printf("Hello from C!\n"); for (int i = 1; i And ready is your cscript :) $ chmod u+x cscript && ./cscript hello world Hello from C! argument 1: hello argument 2: world (I can't even articulate why I love it so much that this works)

Can you change the current working directory? If not, it's not a shell script.

Presumably you can call chdir(2) from the C code?

Or did you mean change the directory of the calling shell (in which case, executable shell scripts written in Bash and friends can’t do that either).

Re: Amber the programming language compiled to Bash/Ksh/Zsh

#27

Hm... But why not use Python

Because it's not preinstalled on every machine. Bash is a good target for portability reasons, but it's a shitty language to write in. If ever I get in the position again to have to write some bash, like for an installer or so, I'm going to be looking into Amber again.

Re: Amber the programming language compiled to Bash/Ksh/Zsh

#29

This looks great. We have a lot of bash tools because it's the only stable interpreter that we have readily available on all our systems. But bash is a pain to write so this might actually make things easier.

How many places do you have Bash, but not AWK?

Or Perl. Or Python. How many environments have only bash and not awk, perl, or python?

Re: Amber the programming language compiled to Bash/Ksh/Zsh

#30

In a world where AI can generate any code for any environment, is there a need for another language? On the other hand, we're at a point for a binary language (or standard / framework) that one AI/LLM creates and another one validates. What are we missing?

Do we really want to stop evolving the space of languages (and libraries and frameworks while we're at it) just because we have LLM's writing code now? If LLM's were truly smart, they'd argue with us that we should stop asking them to write bash code, because it's a shitty error-prone language. True intelligence should be skeptical of itself and not take any request as a requirement.
Post reply on HN