aboutsummaryrefslogtreecommitdiffstats
path: root/check-installed-shebang
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2023-11-18 23:23:40 +0100
committerMattias Andrée <maandree@kth.se>2023-11-18 23:23:40 +0100
commit0f1df0db903ba576fd17b08197d3066af7a61e5f (patch)
treea59c04307b1382257afa3c3512ec3abadf7e0e47 /check-installed-shebang
parentUse losetup -d instead of --detach and add clean up (diff)
downloaddotfiles-0f1df0db903ba576fd17b08197d3066af7a61e5f.tar.gz
dotfiles-0f1df0db903ba576fd17b08197d3066af7a61e5f.tar.bz2
dotfiles-0f1df0db903ba576fd17b08197d3066af7a61e5f.tar.xz
A lot of changes
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'check-installed-shebang')
-rwxr-xr-xcheck-installed-shebang25
1 files changed, 25 insertions, 0 deletions
diff --git a/check-installed-shebang b/check-installed-shebang
new file mode 100755
index 0000000..70bc76e
--- /dev/null
+++ b/check-installed-shebang
@@ -0,0 +1,25 @@
+#!/bin/sh
+set -e
+for f; do
+ test -r "$f"
+ shebang="$(sed 1q < "$f" | \
+ tr '\t' ' ' | \
+ sed -n 's/#! *\([^ ]\+\)\(\| \+.*\)$/\1\n\2/p' | \
+ sed 's/^ *//')"
+ test -n "$shebang"
+ path="$(printf '%s\n' "$shebang" | sed -n 1p)"
+ program="$(printf '%s\n' "$path" | sed 's/^.*\/\([^/]\+\)$/\1/')"
+ arguments="$(printf '%s\n' "$shebang" | sed -n 2p)"
+ argument1="$(printf '%s\n' "$arguments" | cut -d ' ' -f 1)"
+
+ if test -z "$path"; then
+ continue
+ fi
+
+ test -x "$path"
+ if test "$program" = env; then
+ which -- "${arguments}" >/dev/null 2>/dev/null
+ elif test "$program" = shebang; then
+ which -- "${argument1}" >/dev/null 2>/dev/null
+ fi
+done