DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 19th February 2022
stanl stanl is offline
Real Name: Stan
Package Pilot
 
Join Date: Jun 2019
Location: New York
Posts: 163
Default Editing $PATH

Another question which reveals the depth of my ignorance:

rcvstore is an executable file located in /usr/local/libexec/nmh. Why then if I edit my $PATH in ~/.kshrc and add /usr/local/lib/exec/nmh do I not see it? I am editing my ~/.fdm.conf file and I'd like to be able to just write rcvstore +folder instead of /usr/local/libexec/rcstore +folder 25 times.

Thank you
Reply With Quote
  #2   (View Single Post)  
Old 19th February 2022
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 7,983
Default

  1. Unless you have a typo in your post, "lib/exec" and "libexec" are not equivalent.
  2. Take a look at the FILES section of the ksh(1) man page. Note that there is no file named ~/.kshrc.
Reply With Quote
  #3   (View Single Post)  
Old 19th February 2022
stanl stanl is offline
Real Name: Stan
Package Pilot
 
Join Date: Jun 2019
Location: New York
Posts: 163
Default

1. Yes, that was a typo.

2. Sorry, jggimi. I have no idea what you are trying to tell me. The ksh(1) man page mentions the ~/.kshrc file multiple times. I realize I'm being dense but it sounds to me like you're saying ~/.kshrc shouldn't exist which can't be what you're telling me.
Reply With Quote
  #4   (View Single Post)  
Old 19th February 2022
Head_on_a_Stick's Avatar
Head_on_a_Stick Head_on_a_Stick is offline
Real Name: Matthew
Bitchy Nerd Elitist
 
Join Date: Dec 2015
Location: London
Posts: 465
Default

https://man.openbsd.org/ksh#ENV

^ Is that parameter set?

EDIT: anyway the interactive shell configuration file is not the best place to set PATH because it will be read every time a shell is opened and if you're adding directories PATH will become more and more bloated each time.

Use ~/.profile (for console logins) or ~/.xsession (for xenodm) instead.
__________________
Are you infected with Wetiko?

Last edited by Head_on_a_Stick; 19th February 2022 at 02:46 PM.
Reply With Quote
  #5   (View Single Post)  
Old 19th February 2022
stanl stanl is offline
Real Name: Stan
Package Pilot
 
Join Date: Jun 2019
Location: New York
Posts: 163
Default

To say I am confused would be an under statement.
Yes, in my ~/.kshrc the first line is . /etc/ksh.kshrc

If I understand you correctly, you're saying that lines such as export PATH, export editor, etc should go in ~/.profile and not ~/.kshrc?

1) I still don't understand jggimi telling me ~/.kshrc shouldn't exist (which can't be what he's telling me).

This is my PATH entry:
export PATH=$PATH:$HOME/bin:$HOME/.local/bin

2) I don't understand if my PATH is:
export PATH=$PATH:$Home/bin:$HOME/.local/bin

why if I do echo $PATH, the $HOME entries show up twice:
PATH=$PATH:$HOME/bin:$HOME/.local/bin:$HOME/bin:$HOME/.local/bin

And I still have my original question: how can I make it so I don't have to type out the entire /usr/local/libexec/nmh/rcvstore?

Sorry to be so dense. I do appreciate the help.
Thanks
Reply With Quote
  #6   (View Single Post)  
Old 19th February 2022
Head_on_a_Stick's Avatar
Head_on_a_Stick Head_on_a_Stick is offline
Real Name: Matthew
Bitchy Nerd Elitist
 
Join Date: Dec 2015
Location: London
Posts: 465
Default

Quote:
Originally Posted by stanl View Post
If I understand you correctly, you're saying that lines such as export PATH, export editor, etc should go in ~/.profile and not ~/.kshrc?
Yes, that's right.

~/.kshrc (or more accurately "$ENV") is the interactive (non-login) shell configuration file so it is only read when an interactive shell is started. Some parameters may need to be set for the whole login session rather then just for the shell and adding them to "$ENV" would not achieve that.

~/.profile (or ~/.xsession for xenodm sessions) is the appropriate login (non-interactive) shell configuration file for those parameters.

See also https://unix.stackexchange.com/quest...on-login-shell

Quote:
Originally Posted by stanl View Post
I still don't understand jggimi telling me ~/.kshrc shouldn't exist (which can't be what he's telling me).
The interactive (non-login) shell configuration file is set by the "$ENV" parameter. It does not have to be ~/.kshrc and can be called whatever you want as long as the value of "$ENV" is set appropriately.

Quote:
Originally Posted by stanl View Post
why if I do echo $PATH, the $HOME entries show up twice:
PATH=$PATH:$HOME/bin:$HOME/.local/bin:$HOME/bin:$HOME/.local/bin
Because you've opened more than one interactive shell. The PATH will keep growing every time you open another interactive shell (eg, a terminal emulator), as I mentioned in my first post.

That can be prevented by exporting PATH from the login (non-interactive) shell configuration file. Such a file is only read once per session so PATH won't grow.

If you insist on exporting PATH from the interactive (non-login) configuration file you can use something like this to only add the directories to PATH if they are not already present:
Code:
function prepend_path {
   case ":$PATH:" in
      *:"$1":*) ;;
      *) PATH="$1":"${PATH:+$PATH}"
   esac
}

prepend_path "$HOME"/bin
prepend_path "$HOME"/.local/bin

unset -f prepend_path
But I think it would be simpler to use ~/.profile or ~/.xsession

Quote:
Originally Posted by stanl View Post
And I still have my original question: how can I make it so I don't have to type out the entire /usr/local/libexec/nmh/rcvstore?
Remove any PATH settings from "$ENV" and instead add these lines to ~/.profile or ~/.xsession:
Code:
PATH="$HOME"/bin:"$HOME"/.local/bin:/usr/local/libexec/nmh/rcvstore:"$PATH"
export PATH
Note that ~/bin & ~/.local/bin should appear first in PATH so that you can shadow system scripts with your own versions in "$HOME".
__________________
Are you infected with Wetiko?

Last edited by Head_on_a_Stick; 19th February 2022 at 05:44 PM. Reason: removed superfluous curly brackets from "$1"
Reply With Quote
  #7   (View Single Post)  
Old 19th February 2022
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 7,983
Default

Thank you Head....

My reply this morning was before coffee and my apologies to Stanl for being unclear
Reply With Quote
  #8   (View Single Post)  
Old 19th February 2022
stanl stanl is offline
Real Name: Stan
Package Pilot
 
Join Date: Jun 2019
Location: New York
Posts: 163
Default

My ~/.kshrc after editing:

Code:
. /etc/ksh.kshrc
. /home/slaurel/.aliases

PS1='${PWD}$ '
and ~/.profile:

Code:
# $OpenBSD: dot.profile,v 1.5 2018/02/02 02:29:54 yasuoka Exp $
#
# sh/ksh initialization

ENV=$HOME/.kshrc


. /etc/ksh.kshrc
. /home/slaurel/.aliases

export EXA_COLORS="di=34:ex=31:uu=34:gu=36:sn=31:sb=36:*.pdf=30;43:*.html=30;43:*.webm=34;43:*.mkv=34;43"

PATH=$HOME/bin:$HOME/.local/bin:/usr/local/libexec/nmh/rcvstore:"$PATH"

export COLORTERM=truecolor
export LC_CTYPE=en_US.UTF-8
export BROWSER=firefox
export MPD_HOST="localhost"
export MPD_PORT="6600"
export EDITOR=vi
export FCEDIT=$EDITOR
export PAGER=less
export MANPAGER=less
export HISTFILE=$HOME/.ksh_history
export LEDGER_FILE=$HOME/Accounts.dat
export LEDGER_FILE=$HOME/ledger.dat
#export CLICOLOR=1
#export LSCOLORS="exfxbxdxcxegedabagacad"
But still:
Code:
/home/slaurel$ echo $PATH
/home/slaurel/bin:/home/slaurel/.local/bin:/usr/local/libexec/nmh/rcvstore:/home/slaurel/bin:/home/slaurel/.local/bin:/usr/local/libexec/nmh/rcvstore:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin
/home/slaurel$
Also ESC -k no longer cycles thru old commands.

I am really sorry to be such a pain but what am I doing wrong?
Reply With Quote
  #9   (View Single Post)  
Old 19th February 2022
Head_on_a_Stick's Avatar
Head_on_a_Stick Head_on_a_Stick is offline
Real Name: Matthew
Bitchy Nerd Elitist
 
Join Date: Dec 2015
Location: London
Posts: 465
Default

Did you log out & back in again before checking PATH?

Are you using xenodm? If so then please share the content of ~/.xsession

Note that you haven't exported PATH in ~/.profile. I prefer to set the values first then export them separately (as per POSIX) but ksh supports doing both in the same line.

Quote:
Originally Posted by stanl View Post
ESC -k no longer cycles thru old commands
Sounds like EDITOR has not been set. Again, be sure to log out & back in again after adding that parameter to ~/.profile (or ~/.xsession). Use env(1) to list the current environmental parameters.

This will restore vi-like command history browsing in the current session:
Code:
set -o vi
EDIT: off-topic for this thread but ksh allows for GNU-style backslash-escaped special characters so you can use this in ~/.kshrc:
Code:
PS1='\w\$ '
^ That has the advantage of replacing "/home/slaurel" with "~", unlike your current PS1 setting.
__________________
Are you infected with Wetiko?

Last edited by Head_on_a_Stick; 19th February 2022 at 07:57 PM.
Reply With Quote
Old 19th February 2022
stanl stanl is offline
Real Name: Stan
Package Pilot
 
Join Date: Jun 2019
Location: New York
Posts: 163
Default

Before anything, I would like to thank you again for all the time you are taking trying to get me to understand this.

I have always preferred to start X from an ~/.xinitrc file:

Code:
#!/bin/sh
# $OpenBSD: xinitrc.cpp,v 1.13 2015/10/17 08:25:11 matthieu Exp $
#
#
#xsetroot -fg \#6f6f6f -bg \#bfbfbf -bitmap /usr/X11R6/include/X11/bitmaps/root_weave &

xset b off

# To disable screen blanking: xset s off
xset s on +dpms

xrandr --dpi 96

sndioctl output.level=+0.1 &

unclutter -root -idle 2 -noevents &

# xautolock -time 10 -locker slock -detectsleep &

xset fp default
for font in /usr/local/share/fonts/* ; do
           xset fp+ $font
done

xset fp rehash

xinput set-prop "/dev/wsmouse" "WS Pointer Wheel Emulation" 1
xinput set-prop "/dev/wsmouse" "WS Pointer Wheel Emulation Button" 2
xinput set-prop "/dev/wsmouse" "WS Pointer Wheel Emulation Axes" 6 7 4 5
# xinput set-button-map 4 1 1 3

setxkbmap -option ctrl:nocaps # Make caps local a control key

userresources=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
sysresources=/etc/X11/xinit/.Xresources
sysmodmap=/etc/X11/xinit/.Xmodmap
# merge in defaults and keymaps
if [ -f $sysresources ]; then
    xrdb -merge $sysresources
fi
if [ -f $sysmodmap ]; then
    xmodmap $sysmodmap
fi
if [ -f "$userresources" ]; then
    xrdb -merge "$userresources"
fi
if [ -f "$usermodmap" ]; then
    xmodmap "$usermodmap"
fi
# if we have private ssh key(s), start ssh-agent and add the key(s)
id1=$HOME/.ssh/identity
id2=$HOME/.ssh/id_dsa
id3=$HOME/.ssh/id_rsa
id4=$HOME/.ssh/id_ecdsa
id5=$HOME/.ssh/id_ed25519
if [ -z "$SSH_AGENT_PID" ];
then
	if [ -x /usr/bin/ssh-agent ] && [ -f $id1 -o -f $id2 -o -f $id3 -o -f $id4 -o -f $id5 ];
	then
		eval `ssh-agent -s`
		ssh-add < /dev/null
	fi
fi

# If using xintrc to login:
if [ -x ${PREFIX}/bin/dbus-launch -a -z "${DBUS_SESSION_BUS_ADDRESS}" ]; then
  eval `dbus-launch --sh-syntax --exit-with-session`
fi

# If using xenodm to login use:
#if [ -x ${PREFIX}/bin/dbus-launch -a -z "${DBUS_SESSION_BUS_ADDRESS}" ]; then
# eval `dbus-launch --sh-syntax --exit-with-x11`
#fi


# start some nice programs
#mpd ~/.mpd/mpd.conf
# tint2 &
#emacs --bg-daemon
#xclock -d -bg navy -fg orange -geometry -1-1 &
cwm

if [ "$SSH_AGENT_PID" ]; then
	ssh-add -D < /dev/null
	eval `ssh-agent -s -k`
fi
The latest ~/.kshrc and ~/.profile files:

Code:
:
. /etc/ksh.kshrc

set -o vi

alias less='less -IgMw -x2'
alias ls='exa --group-directories-first'
alias la='ls -aF'
alias ll='ls -lhF'
alias df='df -h'
#alias du='du -s * | sort -rnk 1'
alias cp='cp -i'
alias su='su -l'

alias reboot='doas shutdown -r now'
alias shutdown='doas shutdown -p now'

PS1='\w\$ '
Code:
:
# $OpenBSD: dot.profile,v 1.5 2018/02/02 02:29:54 yasuoka Exp $
#
# sh/ksh initialization

ENV=$HOME/.kshrc

export EXA_COLORS="di=34:ex=31:uu=34:gu=36:sn=31:sb=36:*.pdf=30;43:*.html=30;43:*.webm=34;43:*.mkv=34;43"

export PATH=$PATH:$HOME/bin:$HOME/.local/bin:/usr/local/libexec/nmh

export COLORTERM=truecolor
export LC_CTYPE=en_US.UTF-8
export BROWSER=firefox
export MPD_HOST="localhost"
export MPD_PORT="6600"
export EDITOR=vi
export FCEDIT=$EDITOR
export PAGER=less
export MANPAGER=less
export HISTFILE=$HOME/.ksh_history
export LEDGER_FILE=$HOME/Accounts.dat
export LEDGER_FILE=$HOME/ledger.dat
#export CLICOLOR=1
#export LSCOLORS="exfxbxdxcxegedabagacad"
And after echo $PATH:
Code:
~$ echo $PATH
/home/slaurel/bin:/home/slaurel/.local/bin:/usr/local/libexec/nmh:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/home/slaurel/bin:/home/slaurel/.local/bin:/usr/local/libexec/nmh
~$
And I still cannot grasp why /home/slaurel/bin, /home/slaurel/.local/bin and /usr/local/libexec/nmh show up twice.

Thanks
Reply With Quote
Old 19th February 2022
Head_on_a_Stick's Avatar
Head_on_a_Stick Head_on_a_Stick is offline
Real Name: Matthew
Bitchy Nerd Elitist
 
Join Date: Dec 2015
Location: London
Posts: 465
Default

I think this is because of the way you're setting PATH in ~/.profile. The parameter appears to be applied twice but I don't know why.

Try the method used in /etc/skel/.profile (ie, the original version of that file):
Code:
PATH=$HOME/bin:$HOME/.local/bin:/usr/local/libexec/nmh:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/games
export PATH
Or use my prepend_path function to add your desired directories.
__________________
Are you infected with Wetiko?
Reply With Quote
Old 19th February 2022
stanl stanl is offline
Real Name: Stan
Package Pilot
 
Join Date: Jun 2019
Location: New York
Posts: 163
Default

As you suggested, following the example in /etc/skel/.profile works:

Code:
~$ echo $PATH
/home/slaurel/bin:/home/slaurel/.local/bin:/usr/local/libexec/nmh:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/games
~$
You will note I also took your advice regarding the PS1 prompt.

Thank you very much for your time and effort.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Box Wont Boot After Editing /etc/hostname.athn0 EverydayDiesel OpenBSD General 8 10th January 2013 02:31 PM
CFEngine 3.4 adds XML editing and VirtualBox support J65nko News 0 29th November 2012 02:13 PM
add to path carpman FreeBSD General 4 19th August 2010 06:13 AM
Non-root user editing automatically mounted smb share tad1214 FreeBSD General 8 8th July 2008 02:28 AM


All times are GMT. The time now is 01:03 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick