2

I am running the latest OpenBSD and I cannot figure out how to set a simple alias, something along the lines of cls=clear. I've tried putting it in ~/.cshrc and in ~/.profile. I've tried:

alias cls clear
alias cls=clear
alias cls='clear'
alias cls="clear"

Nothing works.

On another but perhaps related note: If echo $SHELL tells me I'm using /bin/ksh, why a ~/.cshrc instead of ~/.kshrc?

  • 2
    What part of the OpenBSD doco told you to use a .cshrc? – JdeBP Oct 17 '18 at 16:30
  • No one told me to use a .cshrc. But when I do a simple install of OpenBSD that's what is created in ~/. – slaurel Oct 17 '18 at 16:41
  • Putting the alias in ~/.profile should have worked; you would have to log out & log in again -- or source the file in the existing shells. Do you still encounter a failure after doing that? – Jeff Schaller Oct 17 '18 at 16:49
  • OK. That works when I first boot up, but if I try it after starting X (startx is how I do it) I get: /bin/ksh:cls: not found – slaurel Oct 17 '18 at 16:57
3

.cshrc is copied over from /etc/skel because it exists there and that's what happens to the contents of /etc/skel on (most) user account additions. However that's totally unrelated to sh or ksh; .cshrc exists due to csh being installed and supported since the 2BSD days (a tradition, at this point).

.profile is only read by login shells, so commands there will not be picked up by new shells that are not login shells:

valen$ cd
valen$ ed .profile
215
a
echo .profile was run
.
wq
237
valen$ exec ksh
valen$ exec ksh -l
.profile was run
valen$ 

The ksh(1) manual has docs on setting an ENV environment variable that non-login instances of ksh will read:

valen$ ed .profile
237
d
a
export ENV=$HOME/.profile
echo now with ENV set
.
wq
263
valen$ exec ksh
valen$ exec ksh -l
now with ENV set
now with ENV set
valen$ exec ksh
now with ENV set
valen$ 

Given the double-read of ~/.profile with export ENV=$HOME/.profile set, it may instead be better to have a different file, such as ~/.kshrc as recommended by the manual that contains your custom aliases:

valen$ cat .profile
PATH=$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/games
export PATH HOME TERM
export ENV=$HOME/.kshrc
valen$ cat .kshrc
alias cls=clear
valen$ exec ksh -l
valen$ alias | grep cls
cls=clear
valen$ 
  • That works. Thanks to both of you for taking the time to help. I appreciate it. – slaurel Oct 17 '18 at 17:10
  • When using X it is better to set ENV to something other than .profile. A good convention is $HOME/.kshrc. Reusing .profile may result in a PATH with duplicate entries in this case. – Henk Langeveld Oct 18 '18 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.