英文:
How do I add these directories to my PATH? Whenever I reboot I have to manually add them again
问题
New to linux terminal, gnome and terminals in general. Thought it would be a good way to learn by customizing UI.
我是新手,对Linux终端、Gnome和终端一般不太了解。想通过自定义UI来学习。
I am trying to automatically add these directories to my PATH instead of doing it manually every time.
To be able to run applications installed by DATLinux distro from my terminal in addition to the applications not in the PATHS below.
我正在尝试自动将这些目录添加到我的PATH,而不是每次都手动添加。这样我就可以在终端中运行DATLinux发行版安装的应用程序,以及下面没有包含在PATH中的应用程序。
I have tried to update .profile and .bashrc at the bottom using vim. With the following.
我已经尝试使用vim在底部更新.profile和.bashrc文件。使用以下内容:
export PATH="/home/oskar/.cari/shims:$PATH"
export PATH="/home/oskar/.cari/bin:$PATH"
export PATH="/home/oskar/.local/bin:$PATH"
OR
或者
export PATH=$PATH:/home/oskar/.cari/shims
export PATH=$PATH:/home/oskar/.cari/bin
export PATH=$PATH:/home/oskar/.local/bin
I am using the Zsh shell
我正在使用Zsh shell。
It works if I manually do it every time.
如果我每次都手动添加它们,它就能正常工作。
Is there not a start up script I could write to do so?
If I run this, would it work:
#!/bin/sh export PATH="/home/oskar/.cari/shims:$PATH" export PATH="/home/oskar/.cari/bin:$PATH" export PATH="/home/oskar/.local/bin:$PATH"
是否没有可以编写的启动脚本来自动添加它们吗?
如果我运行这个脚本,会起作用吗?
#!/bin/sh
export PATH="/home/oskar/.cari/shims:$PATH"
export PATH="/home/oskar/.cari/bin:$PATH"
export PATH="/home/oskar/.local/bin:$PATH"
Here is code for cari.sh, I see I should add "$0" and run the script?
这是cari.sh的代码,我看到我应该添加“$0”并运行脚本?
# 对于Korn shells(ksh,mksh等),立即捕获$_(传递给最后一个命令的最后一个参数),因为它将包含此脚本的路径。
# 对于Bash,${BASH_SOURCE[0]}将用于获取此脚本的路径。
# 对于Zsh和其他shell,$0(shell或脚本的路径)将被使用。
_under="$0"
if [ -z "$CARI_DIR" ]; then
if [ -n "${BASH_SOURCE[0]}" ]; then
current_script_path="${BASH_SOURCE[0]}"
elif [[ "$_under" == *".sh" ]]; then
current_script_path="$_under"
else
current_script_path="$0"
fi
CARI_DIR="$(dirname "$current_script_path")"
fi
export CARI_DIR
# shellcheck disable=SC2016
[ -d "$CARI_DIR" ] || printf '$CARI_DIR is not a directory';
# Add cari to PATH
#
# if in $PATH, remove, regardless of if it is in the right place (at the front) or not.
# replace all occurrences - ${parameter//pattern/string}
CARI_BIN="${CARI_DIR}/bin"
CARI_USER_SHIMS="${CARI_DATA_DIR:-$HOME/.cari}/shims"
[[ ":$PATH:" == *":${CARI_BIN}:"* ]] && PATH="${PATH//$CARI_BIN:/}"
[[ ":$PATH:" == *":${CARI_USER_SHIMS}:"* ]] && PATH="${PATH//$CARI_USER_SHIMS:/}"
# add to the front of $PATH
PATH="${CARI_BIN}:$PATH"
PATH="${CARI_USER_SHIMS}:$PATH"
# shellcheck source=lib/cari.sh
# Load the cari wrapper function
. "${CARI_DIR}/lib/cari.sh"
. "${CARI_DIR}/completions/cari.bash"
unset _under current_script_path CARI_BIN CARI_USER_SHIMS
#!/usr/bin/env bash
# shellcheck source=lib/utils.bash
. "$(dirname "$(dirname "$0")")/lib/utils.bash"
find_cmd() {
local cmd_dir="$1"
shift
local cmd_name
local args_offset="$#"
cmd_name="command-$(tr ' ' '-' <<<"${@:1:${args_offset}}").bash"
while [ ! -f "$cmd_dir/$cmd_name" ] && [ "$args_offset" -gt 0 ]; do
args_offset=$((args_offset - 1))
cmd_name="command-$(tr ' ' '-' <<<"${@:1:${args_offset}}").bash"
done
if [ -f "$cmd_dir/$cmd_name" ]; then
printf "%s %s\n" "$cmd_dir/$cmd_name" "$((args_offset + 1))"
elif [ -f "$cmd_dir/command.bash" ]; then
printf "%s %s\n" "$cmd_dir/command.bash" 1
fi
}
find_cari_cmd() {
local cari_cmd_dir
cari_cmd_dir="$(cari_dir)/lib/commands"
case "$1" in
'add' | \
'current' | \
'env' | \
'exec' | \
'export-shell-version' | \
'global' | \
'install' | \
'info' | \
'install' | \
'latest' | \
'list' | \
'list-all' | \
'plugin-push' | \
'plugins' | \
'remove' | \
'reshim' | \
'shim-versions' | \
'uninstall' | \
'update' | \
'upgrade' | \
'which' )
printf "%s %s\n" "$cari_cmd_dir/command-$1.bash" 2
;;
'' | '--help' | '-h')
printf "%s %s\n" "$cari_cmd_dir/command-help.bash" 2
;;
'--version')
printf "%s %s\n" "$cari_cmd_dir/command-version.bash" 2
;;
*)
find_cmd "$cari_cmd_dir" "$@"
;;
esac
}
find_plugin_cmd() {
local CARI_CMD_FILE args_offset
<details>
<summary>英文:</summary>
New to linux terminal, gnome and terminals in general. Thought it would be a good way to learn by customizing UI.
I am trying to automatically add these directories to my PATH instead of doing it manually every time.
To be able to run applications installed by DATLinux distro from my terminal in addition to the applications not in the PATHS below.
I have tried to update .profile and .bashrc at the bottom using vim. With the following.
export PATH="/home/oskar/.cari/shims:$PATH"
export PATH="/home/oskar/.cari/bin:$PATH"
export PATH="/home/oskar/.local/bin:$PATH"
OR
export PATH=$PATH:/home/oskar/.cari/shims
export PATH=$PATH:/home/oskar/.cari/bin
export PATH=$PATH:/home/oskar/.local/bin
I am using the Zsh shell
It works if I manually do it everytime.
Is there not a start up script i could write to do so?
If i run this would it work:
`#!/bin/sh
export PATH="/home/oskar/.cari/shims:$PATH"
export PATH="/home/oskar/.cari/bin:$PATH"
export PATH="/home/oskar/.local/bin:$PATH"`
Here is code for cari.sh, i see i should add "$0" and run the script?
For Korn shells (ksh, mksh, etc.), capture $_ (the final parameter passed to
the last command) straightaway, as it will contain the path to this script.
For Bash, ${BASH_SOURCE[0]} will be used to obtain this script's path.
For Zsh and others, $0 (the path to the shell or script) will be used.
under="$"
if [ -z "$CARI_DIR" ]; then
if [ -n "${BASH_SOURCE[0]}" ]; then
current_script_path="${BASH_SOURCE[0]}"
elif [[ "$_under" == *".sh" ]]; then
current_script_path="$_under"
else
current_script_path="$0"
fi
CARI_DIR="$(dirname "$current_script_path")"
fi
export CARI_DIR
shellcheck disable=SC2016
[ -d "$CARI_DIR" ] || printf '$CARI_DIR is not a directory'
Add cari to PATH
if in $PATH, remove, regardless of if it is in the right place (at the front) or not.
replace all occurrences - ${parameter//pattern/string}
CARI_BIN="${CARI_DIR}/bin"
CARI_USER_SHIMS="${CARI_DATA_DIR:-$HOME/.cari}/shims"
[[ ":$PATH:" == ":${CARI_BIN}:" ]] && PATH="${PATH//$CARI_BIN:/}"
[[ ":$PATH:" == ":${CARI_USER_SHIMS}:" ]] && PATH="${PATH//$CARI_USER_SHIMS:/}"
add to front of $PATH
PATH="${CARI_BIN}:$PATH"
PATH="${CARI_USER_SHIMS}:$PATH"
shellcheck source=lib/cari.sh
Load the cari wrapper function
. "${CARI_DIR}/lib/cari.sh"
. "${CARI_DIR}/completions/cari.bash"
unset _under current_script_path CARI_BIN CARI_USER_SHIMS
#!/usr/bin/env bash
shellcheck source=lib/utils.bash
. "$(dirname "$(dirname "$0")")/lib/utils.bash"
find_cmd() {
local cmd_dir="$1"
shift
local cmd_name
local args_offset="$#"
cmd_name="command-$(tr ' ' '-' <<<"${@:1:${args_offset}}").bash"
while [ ! -f "$cmd_dir/$cmd_name" ] && [ "$args_offset" -gt 0 ]; do
args_offset=$((args_offset - 1))
cmd_name="command-$(tr ' ' '-' <<<"${@:1:${args_offset}}").bash"
done
if [ -f "$cmd_dir/$cmd_name" ]; then
printf "%s %s\n" "$cmd_dir/$cmd_name" "$((args_offset + 1))"
elif [ -f "$cmd_dir/command.bash" ]; then
printf "%s %s\n" "$cmd_dir/command.bash" 1
fi
}
find_cari_cmd() {
local cari_cmd_dir
cari_cmd_dir="$(cari_dir)/lib/commands"
case "$1" in
'add' |
'current' |
'env' |
'exec' |
'export-shell-version' |
'global' |
'install' |
'info' |
'install' |
'latest' |
'list' |
'list-all' |
'plugin-push' |
'plugins' |
'remove' |
'reshim' |
'shim-versions' |
'uninstall' |
'update' |
'upgrade' |
'which' )
printf "%s %s\n" "$cari_cmd_dir/command-$1.bash" 2
;;
'' | '--help' | '-h')
printf "%s %s\n" "$cari_cmd_dir/command-help.bash" 2
;;
'--version')
printf "%s %s\n" "$cari_cmd_dir/command-version.bash" 2
;;
*)
find_cmd "$cari_cmd_dir" "$@"
;;
esac
}
find_plugin_cmd() {
local CARI_CMD_FILE args_offset
if [ -d "$(get_plugin_path "$1")/bin" ]; then
IFS=' ' read -r CARI_CMD_FILE args_offset <<<"$(find_cmd "$(get_plugin_path "$1")/lib/commands" "${@:2}")"
if [ -n "$CARI_CMD_FILE" ]; then
args_offset=$((args_offset + 1)) # since the first argument is the plugin name
printf "%s %s\n" "$CARI_CMD_FILE" "$args_offset"
fi
fi
}
cari_cmd() {
local CARI_CMD_FILE args_offset
if [ "shell" == "$1" ]; then
printf "Shell integration is not enabled. Please ensure you source cari in your shell setup." >&2
exit 1
fi
IFS=' ' read -r CARI_CMD_FILE args_offset <<<"$(find_cari_cmd "$@")"
if [ -z "$CARI_CMD_FILE" ]; then
IFS=' ' read -r CARI_CMD_FILE args_offset <<<"$(find_plugin_cmd "$@")"
fi
if [ -x "$CARI_CMD_FILE" ]; then
exec "$CARI_CMD_FILE" "${@:${args_offset}}"
elif [ -f "$CARI_CMD_FILE" ]; then
set -- "${@:${args_offset}}"
. "$CARI_CMD_FILE"
else
local cari_cmd_dir
cari_cmd_dir="$(cari_dir)/lib/commands"
printf "%s\n" "Unknown command: `cari ${*}`" >&2
return 127
fi
}
#cari_cmd "$@"
Extract from bash.rc
which_term=ps -o 'cmd=' -p $(ps -o 'ppid=' -p $$)
if [[ $which_term != "gnome-terminal" ]] && [[ $which_term != "datlinux" ]]; then
neofetch
fi
.profile
~/.profile: executed by the command interpreter for login shells.
This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
exists.
see /usr/share/doc/bash/examples/startup-files for examples.
the files are located in the bash-doc package.
the default umask is set in /etc/profile; for setting the umask
for ssh logins, install and configure the libpam-umask package.
#umask 022
if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
if [ -d $HOME/.cari ]; then
export CARI_DIR=$HOME/.cari
export CARI_VENV_PATH=$HOME/.cari/venv
export CARI_PIP_CACHE=$HOME/.pip-cache
. $HOME/.cari/cari.sh
fi
</details>
# 答案1
**得分**: 1
>我已经尝试在底部更新了 .profile 和 .bashrc。
这对于 bash 是可以的,但对于 zsh 不适用。Zsh 不会读取 `.bashrc` 或 `.profile`(除非在 `sh` 或 `ksh` 兼容模式下运行)。相反,您应该使用 `.zshenv`。
如果您想继续使用 `.profile`(如果您选择这样做,应该使其与 bash 和 zsh 兼容),那么创建 `~/.zshenv`:
```shell
. $HOME/.profile
或者直接在 .zshenv
中导出您的 PATH
变量。
英文:
>I have tried to update .profile and .bashrc at the bottom
This is ok for for bash but not for zsh. Zsh does not read .bashrc
or .profile
(unless run in sh
or ksh
compatibility mode). Instead you should use .zshenv
.
If you want to keep using .profile
(if you choose so, you should maintain it compatible for bash and zsh) then create ~/.zshenv
:
. $HOME/.profile
or otherwise export your PATH
variable directly in .zshenv
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论