1diff --git a/craft_parts/executor/step_handler.py b/craft_parts/executor/step_handler.py
2index 5eab915..bc26252 100644
3--- a/craft_parts/executor/step_handler.py
4+++ b/craft_parts/executor/step_handler.py
5@@ -445,7 +445,8 @@ def _create_and_run_script(
6 ) -> None:
7 """Create a script with step-specific commands and execute it."""
8 with script_path.open("w") as run_file:
9- print("#!/bin/bash", file=run_file)
10+ import shutil
11+ print(f"#!{shutil.which('bash')}", file=run_file)
12 print("set -euo pipefail", file=run_file)
13
14 if environment_script_path:
15diff --git a/craft_parts/plugins/java_plugin.py b/craft_parts/plugins/java_plugin.py
16index f2b4064..cb4e9e8 100644
17--- a/craft_parts/plugins/java_plugin.py
18+++ b/craft_parts/plugins/java_plugin.py
19@@ -71,9 +71,8 @@ class JavaPlugin(Plugin):
20 return None, ""
21
22 def _find_javac(self) -> list[str]:
23- cmd = ["find", "/usr/lib/jvm", "-path", "*/bin/javac", "-print"]
24- output = subprocess.check_output(cmd, text=True)
25- return [x for x in output.split("\n") if len(x) > 0]
26+ import shutil
27+ return [shutil.which("javac")]
28
29 @override
30 def get_build_environment(self) -> dict[str, str]:
31diff --git a/craft_parts/plugins/validator.py b/craft_parts/plugins/validator.py
32index 5b4c735..d7a446e 100644
33--- a/craft_parts/plugins/validator.py
34+++ b/craft_parts/plugins/validator.py
35@@ -142,8 +142,9 @@ class PluginEnvironmentValidator:
36 print(cmd, file=env_file)
37 env_file.flush()
38
39+ import shutil
40 proc = subprocess.run(
41- ["/bin/bash", env_file.name],
42+ [shutil.which("bash"), env_file.name],
43 check=True,
44 capture_output=True,
45 text=True,
46diff --git a/tests/unit/executor/test_step_handler.py b/tests/unit/executor/test_step_handler.py
47index 4e73c2b..a5f9374 100644
48--- a/tests/unit/executor/test_step_handler.py
49+++ b/tests/unit/executor/test_step_handler.py
50@@ -209,9 +209,10 @@ class TestStepHandlerBuiltins:
51
52 assert get_mode(build_script_path) == 0o755
53 with open(build_script_path) as file:
54+ import shutil
55 assert file.read() == dedent(
56 f"""\
57- #!/bin/bash
58+ #!{shutil.which("bash")}
59 set -euo pipefail
60 source {environment_script_path}
61 set -x
62diff --git a/tests/unit/utils/test_process.py b/tests/unit/utils/test_process.py
63index a025494..a76cfa2 100644
64--- a/tests/unit/utils/test_process.py
65+++ b/tests/unit/utils/test_process.py
66@@ -33,7 +33,8 @@ _RUN_TEST_CASES = [
67
68 @pytest.mark.parametrize(("out", "err"), _RUN_TEST_CASES)
69 def test_run(out, err):
70- result = process.run(["/usr/bin/sh", "-c", f"echo {out};sleep 0.1;echo {err} >&2"])
71+ import shutil
72+ result = process.run([shutil.which("sh"), "-c", f"echo {out};sleep 0.1;echo {err} >&2"])
73 assert result.returncode == 0
74 assert result.stdout == (out + "\n").encode()
75 assert result.stderr == (err + "\n").encode()
76@@ -42,8 +43,9 @@ def test_run(out, err):
77
78 @pytest.mark.parametrize(("out", "err"), _RUN_TEST_CASES)
79 def test_run_devnull(out, err):
80+ import shutil
81 result = process.run(
82- ["/usr/bin/sh", "-c", f"echo {out};echo {err} >&2"],
83+ [shutil.which("sh"), "-c", f"echo {out};echo {err} >&2"],
84 stdout=subprocess.DEVNULL,
85 stderr=subprocess.DEVNULL,
86 )
87@@ -78,9 +80,10 @@ def test_run_selector(out, err, new_dir):
88
89 selector.register(sock, selectors.EVENT_READ, accept)
90
91+ import shutil
92 result = process.run(
93 [
94- "/usr/bin/sh",
95+ shutil.which("sh"),
96 "-c",
97 f"echo {out};sleep 0.1;echo {err} >&2; echo -n {out}|socat - UNIX-CONNECT:{new_dir}/test.socket",
98 ],