Scripts don't work

When I try to launch a script I get this error
bash: ./script.sh: cannot execute: required file not found
The file is executable and works perfectly on other distros. Do I need to install/enable something to make scripts work?

This is a very basic Linux question and lacking a lot of context, making it very hard to provide a helpful answer.

To start with, you’ve provided an error message, but not what you did to produce it.

What did you enter to run the script?

Second, is the script something you’ve written yourself? Can you share it ( if it isn’t too large)?

2 Likes

Does the file have execute permissions set?

FYI they stated that it is in the original question :slight_smile:

Anyway this is likely a classic case of a script pointing at some shebang that refers to some nonexistent file. If it was a binary executable, a similar error would occur when the executable was linked against some nonexistent library. It working on other distros is probably irrelevant here; on NixOS, both scripts and binaries must be packaged properly to work as you’d hope them to. See Packaging existing software with Nix — nix.dev documentation for a primer.

If this was a binary that attempted to use the global dynamic linker, you’d get a more user-friendly error message because of stub-ld.

Right, because all the bash scripts I have begin with #!/bin/bash, it went completely unnoticed, sorry, what should I use in NixOS?

/usr/bin/env bash or /bin/sh.

You can also run a script using bash path/to/script.

1 Like

Thank you. #!/usr/bin/env bash should also be compatible with all other distros, right? Thanks a lot

Yes, practically any distro will have /usr/bin/env. Though not necessarily all of them will have bash.

3 Likes

Repeating again: [quote=“waffle8946, post:4, topic:57923”]
both scripts and binaries must be packaged properly to work as you’d hope them to
[/quote]

If your script doesn’t work as expected after fixing the shebang, it’s likely not packaged for nixos.

It sounds like you want your script to work on multiple distros. Here’s an example project that packages complex scripts for multiple distros including nixos: GitHub - quickemu-project/quickemu: Quickly create and run optimised Windows, macOS and Linux virtual machines

1 Like