LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 02-11-2022, 10:19 PM   #1
thirdm
Member
 
Registered: May 2013
Location: Massachusetts
Distribution: Slackware, NetBSD, Debian, 9front
Posts: 327

Rep: Reputation: Disabled
ksh PS1 in /etc/profile needs to escape tilde


The ksh man page section Tilde Substitution is somewhat confusing, but I think ~ expands in ${PWD/#$HOME/~} so that $HOME is being replaced with what ~ expands to which is the same as $HOME (assuming you don't have /home -> /usr/local/home/ messing things up completely)...

/etc/profile:
Code:
elif [ "$SHELL" = "/bin/ksh" ]; then
 PS1='! ${PWD/#$HOME/~}$ '
elif [ "$SHELL" = "/bin/zsh" ]; then

Quote:
748r0:root# PS1='! ${PWD/#$HOME/~}$ '
749 /root$ PS1='! ${PWD/#$HOME/\~}$ '
750 ~$
This is 14.2, but I first noticed it while playing with 15 on a Mac Book Air, so it's both places I think.
 
Old 02-12-2022, 04:42 AM   #2
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,927

Rep: Reputation: 5043Reputation: 5043Reputation: 5043Reputation: 5043Reputation: 5043Reputation: 5043Reputation: 5043Reputation: 5043Reputation: 5043Reputation: 5043Reputation: 5043
Yep, I think you're right. Thanks,

There's a number of other things wrong with /etc/profile.
I posted some "observations" a long time ago, but most of them are still unaddressed.

On my install, I stripped all the prompt setting code out into a profile.d/prompt.sh:
Code:
#!/bin/false  # /etc/profile.d/prompt.sh ############################
#
#  Set an appropriate shell prompt string for the invoking shell:
#
#  Notes:
#
#   o  $SHELL is not a reliable way of identifying the specific
#      shell implementation that is invoking /etc/profile.
#      $0 is a little more reliable, except that zsh treats it
#      differently to everything else when it's sourcing files. :(
#      Therefore, we have to use ${ZSH_ARGZERO:-$0} to cater for
#      zsh.
#
#   o  DO NOT EXPORT PS1!
#      Any use of shell specific syntax in the prompt string will 
#      result in a messed up prompt when using nested invocations of
#      other shell implementations. Besides, 'bash' has a tendency to
#      unset the variable when used non-interactively, so, the chances
#      are that it'll just be lost somewhere down the environment
#      inheritance chain anyway.
#
#   o  /etc/profile is not invoked by non-login shells, so users
#      wuuld do better to set their desired prompt in their shell
#      specific startup files, such as ~/.bashrc.
#
#      Traditional UNIX shells that are 'interactive' will always
#      source their startup file (pointed to by $ENV) regardless of
#      whether they are 'login-shells' or not, but bash does not do
#      this unless invoked as 'sh'.  A workaround for this is
#      to source ~/.bashrc from your ~/.bash_profile.
#

case $- in
    *i*)  # interactive shell
	  case "${ZSH_ARGZERO:-$0}" in  # zsh shenanigans!
	      -bash|bash|*/bash )     PS1='\u@\h:\w\$ '          ;;
	      -ksh|ksh|*/ksh )        PS1='! ${PWD/#$HOME/\~}$ ' ;;
	      -pdksh|pdksh|*/pdksh )  PS1='! $ '                 ;;
	      -zsh|zsh|*/zsh )        PS1='%n@%m:%~%# '          ;;
	      *)                      PS1="$ "                   ;;
	  esac
	  ;;
esac

########################################################################
(including your fix for ksh )

Last edited by GazL; 02-12-2022 at 04:45 AM.
 
2 members found this post helpful.
Old 02-12-2022, 09:12 AM   #3
thirdm
Member
 
Registered: May 2013
Location: Massachusetts
Distribution: Slackware, NetBSD, Debian, 9front
Posts: 327

Original Poster
Rep: Reputation: Disabled
These seem good points. But if the third is addressed does that mean no Slackware suggested PS1? I wouldn't have thought of replacing $HOME with ~, so benefited from (eventually) noticing the PS1 in /etc/profile. That could be solved by providing .kshrc, .bashrc, etc. example files in whatever the standard location for example configuration is in Slackware, I suppose.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] ksh .profile, customized prompt PS1 does not work B612 Linux - General 6 12-06-2020 06:41 AM
shell: how to escape (or not escape) $ within an echo statement? Paul_N Linux - Newbie 2 04-05-2016 01:59 AM
Tilde / back-tick key not giving me a tilde or back-tic. Ubuntu 10.04 on Macbook Pro BrianK Linux - Laptop and Netbook 3 09-01-2015 09:14 PM
[SOLVED] Redirect tilde addresses to non-tilde Cyrolancer Linux - Server 11 01-09-2013 04:25 AM
RHEL5 X-windows login- /etc/profile not being used by KSH users only caseybea Red Hat 0 06-03-2008 10:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 05:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration