News for hackers. Stuff that matters.
Re:Amber the programming language compiled to Bash/Ksh/Zsh by b-kf on Saturday July 11, 2026 @03:20PM (#48874927)
Exactly

  #!/usr/bin/tcc -run
  
  #include <stdio.h>
  
  int main(int argc, char **argv)
  {
      printf("Hello from C!\n");
  
      for (int i = 1; i < argc; ++i)
          printf("argument %d: %s\n", i, argv[i]);
  
      return 0;
  }
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)
Re:Amber the programming language compiled to Bash/Ksh/Zsh by xixixao on Saturday July 11, 2026 @03:58PM (#48875284)
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 by b-kf on Saturday July 11, 2026 @04:38PM (#48875623)
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 <stdio.h>
  #include <stdlib.h>
  #include <unistd.h>
    
  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 by zbentley on Saturday July 11, 2026 @04:40PM (#48875640)
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 by wavemode on Saturday July 11, 2026 @05:02PM (#48875857)
Well, you can "source" a script, so its effects persist in your current shell session. That's a feature of the script and your shell sharing the same language.
Re:Amber the programming language compiled to Bash/Ksh/Zsh by freehorse on Saturday July 11, 2026 @07:11PM (#48876723)
Then it seems that what you want is running a repl of your chosen language rather than shell/"executable" scripts.
Re:Amber the programming language compiled to Bash/Ksh/Zsh by zbentley on Saturday July 11, 2026 @06:19PM (#48876377)
Sure, but “shell scripts” as an (admittedly imprecise) term usually imply separate executable files, not shell libraries/functions that are sourced.
Re:Amber the programming language compiled to Bash/Ksh/Zsh by ivanjermakov on Saturday July 11, 2026 @06:39PM (#48876519)
Of course you can. How do you think `cd` utility is implemented?
Re:Amber the programming language compiled to Bash/Ksh/Zsh by xigoi on Sunday July 12, 2026 @05:00AM (#48879542)
cd is a shell built-in, not a script.