( and ) causes syntax error

Hi everyone . İ tried to create mini script on @NobbZ 's script. But it includes ( ) these symbols for python. So i fail. How to solve it. İ tried to add it from configuration.nix and its writeShellScriptBin. İt gets error on os.system
2022-06-14T17:10:30,459126162+03:00

You’re using writeShellScriptBin, which IIRC runs a syntax check on the script. If you’re going to put Python in it, you probably want to use writeScriptBin.

3 Likes

Not just that, it also puts a shebang in the file for you. Which means your script will look like this:

#!/nix/store/something-bash/bin/bash
#!/nix/store/something-python/bin/python
<some python code>

So even if there were no syntax checking, you’ll end up with a python script executed by bash.

If you want a python script, may I suggest writePython3Bin, which does what writeShellScriptBin does but for python? E.g.:

pkgs.writers.writePython3Bin "python-test" {} ''
  import os

  os.system("${libnotify}/bin/notify-send test")
''
2 Likes

The others already said how to fix the problem, though please in the future also:

  1. Do not paste screenshots of code, but use triple-backticks and paste in actual code, like this:
    ```nix
    (writeShellScriptBin "name" ''
      scriptContent
    '')
    ```
    
  2. Also please always also paste the actual error message you get, it is much easier to tell you what the problem is.
5 Likes