Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Other Things Gentoo
  • Search

export path not working in zsh

Still need help with Gentoo, and your question doesn't fit in the above forums? Here is your last bastion of hope.
Post Reply
Advanced search
16 posts • Page 1 of 1
Author
Message
VargFren
n00b
n00b
Posts: 9
Joined: Tue Jul 20, 2021 8:18 pm

export path not working in zsh

  • Quote

Post by VargFren » Wed Jul 21, 2021 3:38 am

Hi, this is my first time posting in here, i recently installed gentoo and i was able to setup my working environment, however, i'm facing a problem with zsh export PATH

I've this inside my .zshenv

Code: Select all

export PATH="$HOME/.local/bin:$HOME/.local/bin/Personal:$PATH"
but for some reason when i made

Code: Select all

echo $PATH
i only get this:

Code: Select all

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/lib/llvm/12/bin
I've read in the arch wiki that the order in which zsh files are load is

Code: Select all

/etc/zsh/zshenv
$ZDOTDIR/.zshenv
/etc/zsh/zprofile
/etc/profile
$ZDOTDIR/.zprofile
/etc/zsh/zshrc
$ZDOTDIR/.zshrc
/etc/zsh/zlogin
$ZDOTDIR/.zlogin
$ZDOTDIR/.zlogout
/etc/zsh/zlogout
so my .zshenv is gonna load before the /etc/zsh/zprofile which will source /etc/profile and override my $PATH variable, how can i avoid this?
Top
fedeliallalinea
Administrator
Administrator
User avatar
Posts: 31985
Joined: Sat Mar 08, 2003 11:15 pm
Location: here
Contact:
Contact fedeliallalinea
Website

  • Quote

Post by fedeliallalinea » Wed Jul 21, 2021 4:51 am

Welcome to gentoo.

I tried and adding PATH in ~/.zshenv this is loaded correctly

Code: Select all

$ echo 'export PATH="/home/test/.local/bin:/home/test/.local/bin/Personal:$PATH"' > ~/.zshenv
$ zsh
$ echo $PATH            
/home/test/.local/bin:/home/test/.local/bin/Personal:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin
Questions are guaranteed in life; Answers aren't.

"Those who would give up essential liberty to purchase a little temporary safety,
deserve neither liberty nor safety."
- Ben Franklin
https://www.news.admin.ch/it/nsb?id=103968
Top
VargFren
n00b
n00b
Posts: 9
Joined: Tue Jul 20, 2021 8:18 pm

  • Quote

Post by VargFren » Wed Jul 21, 2021 12:54 pm

fedeliallalinea wrote:Welcome to gentoo.

I tried and adding PATH in ~/.zshenv this is loaded correctly

Code: Select all

$ echo 'export PATH="/home/test/.local/bin:/home/test/.local/bin/Personal:$PATH"' > ~/.zshenv
$ zsh
$ echo $PATH            
/home/test/.local/bin:/home/test/.local/bin/Personal:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin
Hi, i already tried this like a million times, there is something that override my path at some point, and probably that's why i cannot recreate the above example :( another idea?
For reference, this is my full .zshenv file

Code: Select all

# Environmental variables are set here.

# Default programs:
# Editor
export EDITOR="vim"
export VISUAL="vim"

export TERMINAL="st"
export BROWSER="firefox"
export READER="zathura"
export IMAGE_VIEWER="sxiv"
export WM="bspwm"

# PATH
export PATH="$HOME/.local/bin:$HOME/.local/bin/Personal:$PATH"

# XDG
export XDG_CONFIG_HOME="$HOME/.config/"
export XDG_DATA_HOME="$HOME/.local/share"
export XDG_CACHE_HOME="$HOME/.cache"

# ZSH
export ZDOTDIR="$XDG_CONFIG_HOME/zsh"
export HISTFILE="$ZDOTDIR/.zhistory"
export HISTSIZE=100000
export SAVEHIST=100000

# X11
export XINITRC="$HOME/.config/X11/xinitrc"

# Clean Up
export XAUTHORITY="$XDG_RUNTIME_DIR/Xauthority"
export LESSHISTFILE="-"
export WGETRC="$XDG_CONFIG_HOME/wget/wgetrc"
Everything else in that file is currently working, only export path is giving me the headache
Top
fedeliallalinea
Administrator
Administrator
User avatar
Posts: 31985
Joined: Sat Mar 08, 2003 11:15 pm
Location: here
Contact:
Contact fedeliallalinea
Website

  • Quote

Post by fedeliallalinea » Wed Jul 21, 2021 1:00 pm

You already create a .zshenv with only export PATH?
Try to see if grep PATH ~/.z* command return something.
Questions are guaranteed in life; Answers aren't.

"Those who would give up essential liberty to purchase a little temporary safety,
deserve neither liberty nor safety."
- Ben Franklin
https://www.news.admin.ch/it/nsb?id=103968
Top
VargFren
n00b
n00b
Posts: 9
Joined: Tue Jul 20, 2021 8:18 pm

  • Quote

Post by VargFren » Wed Jul 21, 2021 1:18 pm

fedeliallalinea wrote:You already create a .zshenv with only export PATH?
Try to see if grep PATH ~/.z* command return something.
It didn't work, echo $PATH only shows the same thing.
Top
fedeliallalinea
Administrator
Administrator
User avatar
Posts: 31985
Joined: Sat Mar 08, 2003 11:15 pm
Location: here
Contact:
Contact fedeliallalinea
Website

  • Quote

Post by fedeliallalinea » Wed Jul 21, 2021 3:38 pm

I tried in two system with zsh and works, so you have changed/created a file that override PATH variable.
Questions are guaranteed in life; Answers aren't.

"Those who would give up essential liberty to purchase a little temporary safety,
deserve neither liberty nor safety."
- Ben Franklin
https://www.news.admin.ch/it/nsb?id=103968
Top
Hu
Administrator
Administrator
Posts: 24401
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Wed Jul 21, 2021 4:13 pm

You need to find what file(s) are resetting your path. Bash has set -x to enable xtrace mode, which would lead you to it. Perhaps zsh has something similar.
Top
VargFren
n00b
n00b
Posts: 9
Joined: Tue Jul 20, 2021 8:18 pm

  • Quote

Post by VargFren » Thu Jul 22, 2021 8:00 pm

Please take a look at my zsh config, and tell me if something is causing this issue, i wasn't able to figure out myself :( I keep struggling with this since i have a lot of scripts inside ~/.local/bin

And at this stage i'm not able to execute any of they without sourcing the .zshenv before which is such a pain in the ass. I know i could source .zshenv inside .xinitrc, but i would rather prefer the zsh prompt to do his own thing automatically.
  • .zshenv

    Code: Select all

    # Environmental variables are set here.
    
    # Default programs
    export EDITOR="vim"
    export VISUAL="vim"
    export TERMINAL="st"
    export BROWSER="firefox"
    export READER="zathura"
    export IMAGE_VIEWER="sxiv"
    export WM="bspwm"
    
    # PATH
    export PATH="$HOME/.local/bin:$PATH"
    
    # XDG
    export XDG_CONFIG_HOME="$HOME/.config"
    export XDG_DATA_HOME="$HOME/.local/share"
    export XDG_CACHE_HOME="$HOME/.cache"
    
    # ZSH
    export ZDOTDIR="$XDG_CONFIG_HOME/zsh"
    export HISTFILE="$ZDOTDIR/.zhistory"
    export HISTSIZE=100000
    export SAVEHIST=100000
    
    # X11
    export XINITRC="$HOME/.config/X11/xinitrc"
    
    # Clean Up
    export XAUTHORITY="$XDG_RUNTIME_DIR/Xauthority"
    export LESSHISTFILE="-"
    export WGETRC="$XDG_CONFIG_HOME/wget/wgetrc"
    
  • .zprofile

    Code: Select all

    if [[ "$(tty)" = "/dev/tty1" ]]; then
            pgrep bspwm || exec startx "$XINITRC" > /dev/null 2>&1
    fi
    
  • .zshrc

    Code: Select all

    # If not running interactively, don't do anything
    [[ $- != *i* ]] && return
    
    # Navigation
    setopt AUTO_CD                  # Go to folder path without using cd.
    setopt EXTENDED_GLOB            # Use extended globbing syntax.
    setopt AUTO_PUSHD               # Push the old directory onto the stack on cd.
    setopt PUSHD_IGNORE_DUPS        # Do not store duplicates in the stack.
    setopt PUSHD_SILENT             # Do not print the directory stack after pushd or popd
    
    # History
    setopt SHARE_HISTORY            # Share history between all sessions.
    setopt HIST_EXPIRE_DUPS_FIRST   # Expire a duplicate event first when trimming history.
    setopt HIST_IGNORE_DUPS         # Do not record an event that was just recorded.
    setopt HIST_IGNORE_ALL_DUPS     # Delete an old record even if a new event is duplicate.
    setopt HIST_FIND_NO_DUPS        # Do not display a previously found event.
    setopt HIST_IGNORE_SPACE        # Do not record an event starting with space.
    setopt HIST_VERIFY              # Do not execute inmediately upon history expansion.
    
    fpath+=$ZDOTDIR/prompt
    
    autoload -U promptinit; promptinit
    prompt pure
    
    # Load aliases and shortcuts if existent
    source $ZDOTDIR/aliasrc
    
    # Basic auto/tab complete
    autoload -Uz compinit; compinit -i
    _comp_options+=(globdots)
    source $ZDOTDIR/completion.zsh
    
    # VI Mode
    bindkey -v
    export KEYTIMEOUT=1
    
    # Change cursor shape for different vi modes.
    source $ZDOTDIR/cursor_mode
    
    # Use vim keys in tab complete menu
    zmodload zsh/complist
    bindkey -M menuselect 'h' vi-backward-char
    bindkey -M menuselect 'k' vi-up-line-or-history
    bindkey -M menuselect 'l' vi-forward-char
    bindkey -M menuselect 'j' vi-down-line-or-history
    # Fix backspace bug when switching modes
    bindkey "^?" backward-delete-char
    
    # Edit the current command line with $EDITOR (vi-mode, then v)
    autoload -Uz edit-command-line
    zle -N edit-command-line
    bindkey -M vicmd v edit-command-line
    
Top
VargFren
n00b
n00b
Posts: 9
Joined: Tue Jul 20, 2021 8:18 pm

  • Quote

Post by VargFren » Thu Jul 22, 2021 8:03 pm

Keep in mind that this is a fresh installation of zsh, I have not touched any of the files that come by default within /etc/zsh, so I am sure that this is a problem with zsh itself
Top
Hu
Administrator
Administrator
Posts: 24401
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Thu Jul 22, 2021 9:54 pm

None of that looks obviously wrong to me. Did xtrace mode not help?
Top
VargFren
n00b
n00b
Posts: 9
Joined: Tue Jul 20, 2021 8:18 pm

  • Quote

Post by VargFren » Fri Jul 23, 2021 1:42 pm

Hu wrote:None of that looks obviously wrong to me. Did xtrace mode not help?

I'm confused about how to use xtrace to check if path is being overrided, can you provide an example?
Top
fedeliallalinea
Administrator
Administrator
User avatar
Posts: 31985
Joined: Sat Mar 08, 2003 11:15 pm
Location: here
Contact:
Contact fedeliallalinea
Website

  • Quote

Post by fedeliallalinea » Fri Jul 23, 2021 1:54 pm

Run zsh -i -x -c exit &> /tmp/zsh-output-debug.txt command, then read /tmp/zsh-output-debug.txt file
Questions are guaranteed in life; Answers aren't.

"Those who would give up essential liberty to purchase a little temporary safety,
deserve neither liberty nor safety."
- Ben Franklin
https://www.news.admin.ch/it/nsb?id=103968
Top
VargFren
n00b
n00b
Posts: 9
Joined: Tue Jul 20, 2021 8:18 pm

  • Quote

Post by VargFren » Fri Jul 23, 2021 3:04 pm

fedeliallalinea wrote:Run zsh -i -x -c exit &> /tmp/zsh-output-debug.txt command, then read /tmp/zsh-output-debug.txt file
Ok, so i've done this
  • disable zsh prompt theme
  • disable other things inside my .zshenv
  • delete my .zshrc
the result of the above command is:

Code: Select all

+/home/myusername/.zshenv:13> export PATH=/home/myusername/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/lib/llvm/12/bin
+zsh:1> exit
to my understanding, the zsh prompt is exporting the PATH variable as expected, however running echo $PATH does not show my .local/bin folder, so i guess something external is overriding the path.

I've also tried this
  • create a new user called zshuser
  • assign home folder and zsh prompt
  • create a file .zshenv with only export path statement
  • logout and login
  • echo $PATH
  • .local/bin/ is not in $PATH
Finally i think every time i log in with zsh the default files within /etc/ are the responsible of overriding my path, an inspection to /etc/zsh/zprofile show this

Code: Select all

# /etc/zsh/zprofile

# Load environment settings from profile.env, which is created by
# env-update from the files in /etc/env.d
if [[ -e /etc/profile.env ]] ; then
        . /etc/profile.env
fi

# You should override these in your ~/.zprofile (or equivalent) for per-user
# settings.  For system defaults, you can add a new file in /etc/profile.d/.
export EDITOR=${EDITOR:-/bin/nano}
export PAGER=${PAGER:-/usr/bin/less}

# 077 would be more secure, but 022 is generally quite realistic
umask 022

# Set up PATH depending on whether we're root or a normal user.
# There's no real reason to exclude sbin paths from the normal user,
# but it can make tab-completion easier when they aren't in the
# user's PATH to pollute the executable namespace.
#
# It is intentional in the following line to use || instead of -o.
# This way the evaluation can be short-circuited and calling whoami is
# avoided.
if [[ "$EUID" = "0" ]] || [[ "$USER" = "root" ]] ; then
        # Check to make sure ROOTPATH is sane before we use it.
        # https://bugs.gentoo.org/656400
        if [[ :${ROOTPATH}: == *:/usr/sbin:* ]]; then
                PATH="${ROOTPATH}"
        fi
fi
export PATH
unset ROOTPATH

shopts=$-
setopt nullglob
for sh in /etc/profile.d/*.sh ; do
        [[ -r "${sh}" ]] && . "${sh}"
done
unsetopt nullglob
set -$shopts
unset sh shopts
at the top of the file is sourcing /etc/profile.env

Code: Select all

# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.
# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES
# GO INTO /etc/profile NOT /etc/profile.env

export CONFIG_PROTECT='/usr/share/gnupg/qualified.txt'
export CONFIG_PROTECT_MASK='/etc/sandbox.d /etc/fonts/fonts.conf /etc/gentoo-release /etc/terminfo /etc/ca-certificates.conf'
export GCC_SPECS=''
export INFOPATH='/usr/share/gcc-data/x86_64-pc-linux-gnu/10.3.0/info:/usr/share/binutils-data/x86_64-pc-linux-gnu/2.35.2/info:/usr/share/info'
export LANG='en_US.utf8'
export LESS='-R -M --shift 5'
export LESSOPEN='|lesspipe %s'
export MANPAGER='manpager'
export MANPATH='/usr/share/gcc-data/x86_64-pc-linux-gnu/10.3.0/man:/usr/share/binutils-data/x86_64-pc-linux-gnu/2.35.2/man:/usr/local/share/man:/usr/share/man:/usr/lib/rust/man:/usr/lib/llvm/12/share/man'
export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/lib/llvm/12/bin'
export ROOTPATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/lib/llvm/12/bin'
so as you can see in the above code, /etc/profile.env is overriding the path variable acording to the arch wiki info

Code: Select all

/etc/zsh/zshenv
$ZDOTDIR/.zshenv <- Here is where i defined my .local/bin/ path
/etc/zsh/zprofile <- The default zprofile sources the /etc/profile.env causing the issue
/etc/profile
$ZDOTDIR/.zprofile
/etc/zsh/zshrc
$ZDOTDIR/.zshrc
/etc/zsh/zlogin
$ZDOTDIR/.zlogin
$ZDOTDIR/.zlogout
/etc/zsh/zlogout
Now i understand the problem, but then how can i export my path? since using .zshrc is not a good place to put your env variables.

Do you think it would be a good idea to delete/override the default /etc/zsh files? I would prefer not to do it, but i'm running out of ideas

The /etc/profile.env file is generated by env-update, which i used during the gentoo installation, so i'm very unsure of what to do now :?
Top
Hu
Administrator
Administrator
Posts: 24401
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Fri Jul 23, 2021 3:32 pm

You could use .zprofile. That looks to be the zsh equivalent of .bash_profile, which is commonly used by Bash users to set their login environment. According to your output, .zprofile is loaded after /etc/profile.
Top
VargFren
n00b
n00b
Posts: 9
Joined: Tue Jul 20, 2021 8:18 pm

  • Quote

Post by VargFren » Fri Jul 23, 2021 4:05 pm

Hu wrote:You could use .zprofile. That looks to be the zsh equivalent of .bash_profile, which is commonly used by Bash users to set their login environment. According to your output, .zprofile is loaded after /etc/profile.
Thanks, works like a charm :D i'm marking this as solved.

However, the fact you cannot export the path within .zshenv by default is annoying af. There should be a reason why this work the way it do out the box. I hope someone wiser can explain this.
Top
Hu
Administrator
Administrator
Posts: 24401
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Fri Jul 23, 2021 5:06 pm

You can export it there. It's then reset by /etc/profile.env, so it's only usefully exported in .zshenv until the end of that file. By the time you get interactive access to the shell, it has long since been reset.. Bash has no equivalent of .zshenv, so Bash users don't notice this.
Top
Post Reply

16 posts • Page 1 of 1

Return to “Other Things Gentoo”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic