WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: path2.sh aka "$( which $1 )"  (Read 312 times)

Offline mocore

  • Hero Member
  • *****
  • Posts: 633
  • ~.~
path2.sh aka "$( which $1 )"
« on: August 31, 2024, 08:01:52 AM »
a script for those to lazy or board of repeatedly  typing
nano $(which _some_script_in_path_ )
ect .. 

Code: [Select]
#path2.sh
# echo(default) full path to any script in $PATH ,
# optionally prefix the cmd_path with other command eg nano/cat/file ect   
 [ -z $dbg ] || set -x ; #
 _cmd=$1
 _run=${2-echo} # set default to echo

 [ $# -eq 1 ] && shift     # enable extra args
 [ $# -eq 2 ] && shift 2

 cmd_path=$( which $_cmd )

 # run cmd passing  args 
 $_run $cmd_path  "$@"


 

Quote
#eg

# edit this(or any other) script ( in $PATH )
# path2.sh path2.sh nano

#- print this script
#  path2.sh path2.sh cat

#- debug this script
# path2.sh path2.sh "sh -x"

#- WTF
# export dbg=y path2.sh path2.sh "exec" path2.sh cat

 :o


(obviously) simpler yet also
similar in some ways (prefixing & arg juggling ) to : ' a shell repl function ' https://forum.tinycorelinux.net/index.php/topic,26193.0.html
aka * https://github.com/mchav/with -  Command prefixing for continuous workflow using a single tool.
*mchav/with requires bash
« Last Edit: August 31, 2024, 08:29:14 AM by mocore »

Offline mocore

  • Hero Member
  • *****
  • Posts: 633
  • ~.~
Re: path2.sh wrt PATH
« Reply #1 on: August 31, 2024, 09:14:43 AM »

for those who are forgetful/unfamiliar with the concept
its useful because it helps u type less  ;)

Quote
The PATH variable makes it easy to run commonly used programs located in their own folders.
https://en.wikipedia.org/wiki/PATH_(variable)

from a topic about
modifying PATH in core
Hi PDP-8
Take a look inside  ~/.profile  for adding paths.

on a bit of a tangent wrt .profile

Looks like additions to  .profile  probably need to be added above this section of the file in order to be seen:
Code: [Select]
TERMTYPE=`/usr/bin/tty`
[ ${TERMTYPE:5:3} == "tty" ] && (
[ ! -f /etc/sysconfig/Xserver ] ||
[ -f /etc/sysconfig/text ] ||
[ -e /tmp/.X11-unix/X0 ] ||
startx
)


generally on the topic
 https://unix.stackexchange.com/questions/227989/complete-view-of-where-the-path-variable-is-set-in-bash