Sample Header Ad - 728x90

How to trim directory from which output without basename?

-2 votes
1 answer
115 views
For a shell script I need to call an executable by name, regardless of the path leading there; thus far I know this code reports the right name:
tmpprog=which program
prog=${tmpprog%%*/}
if $prog=""
then
  echo >&2 "Main Program not found"
else
  echo >&2 "$prog"
fi
How can I cut the code so that I may trim the path to keep the executable name and remove the path in a one liner? Beware: basename won't do it, since I may be working on a hybrid environment (cygwin/busybox on windoze), and sometimes the paths have spaces.
Asked by jarnowy (200 rep)
Jan 16, 2024, 02:14 AM
Last activity: Apr 5, 2024, 08:31 AM