TRYEXEC(1)

πŸ“¦ version 2.9.9.2, in nixpkgs unstable

πŸ’… tryexec β€” execute into a command line, with a fallback ✨

hii bestie 🫢 this is tryexec(1) from the General Commands Manual, and it is genuinely such a useful little exec gremlin. no cap, the whole point is: try one command line, and if that fails, fall back to another one. πŸ’–


🌸 NAME 🌸

tryexec β€” execute into a command line, with a fallback. that's the whole vibe. πŸ’…

πŸ¦‹ SYNOPSIS πŸ¦‹

inside an execlineb(1) script, bestie, it looks like this:

tryexec [-n] [-c] [-l] [-a argv0] { prog1... } prog2...

✨ DESCRIPTION ✨

okay so tryexec reads prog1... in a block (cf. execline-block(7)). then it executes into that block, and it completely forgets prog2.... like, gone. not invited to the exec party anymore. πŸ’€

but if for some reason the execve(2) fails β€” for instance, because prog1 is non-executable β€” then tryexec executes into prog2... instead. fallback era. πŸ™ˆ

for the record, tryexec prog1... "" prog2... would be equivalent to sh -c 'exec prog1... || exec prog2...', if such a shell construct existed. unfortunately, the shell language does not offer that functionality. and that's the lore. πŸ“–

πŸ’… OPTIONS πŸ’…

the -c, -l and -a options have the same semantics as with the exec(1) program β€” go check that icon if you need the details, bestie. πŸ’–

  • -n β€” reverse prog1... and prog2...'s role. the latter becomes the main execution path, and the former becomes the fallback. plot twist. πŸ”₯
  • -c β€” same semantics as with the exec(1) program.
  • -l β€” same semantics as with the exec(1) program.
  • -a argv0 β€” same semantics as with the exec(1) program.

🌈 SEE ALSO 🌈

go stalk these icons: emptyenv(1), envfile(1), exec(1), execline-cd(1), execline-umask(1), execlineb(1), exit(1), export(1), fdblock(1), fdclose(1), fdmove(1), fdreserve(1), fdswap(1), getcwd(1), getpid(1), heredoc(1), piperw(1), posix-cd(1), posix-umask(1), redirfd(1), trap(1), unexport(1), wait(1), withstdinas(1), execve(2), execline-block(7).

this man page is ported from the authoritative documentation at https://skarnet.org/software/execline/tryexec.html. 🫢

πŸ‘‘ AUTHORS πŸ‘‘

  • Laurent Bercot
  • Alexis <flexibeast@gmail.com> (man page port)

Debian, February 14, 2021 β€” mwah, bye bestie! πŸ’‹

πŸ“¦ where this page comes from