AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题

问题[bashrc](ubuntu)

Martin Hope
MohammadBaqer
Asked: 2022-10-08 01:15:08 +0800 CST

每个命令都需要 export PATH="/usr/bin:$PATH"

  • 2

所以我试图设置 JAVA_HOME 变量,以及每次我想使用终端时我最终遇到这个错误的方式

Command 'poweroff' is available in the following places
* /sbin/poweroff
* /usr/sbin/poweroff
The command could not be located because '/sbin:/usr/sbin' is not included in the 
PATH environment variable.
This is most likely caused by the lack of administrative privileges associated with 
your user account.
poweroff: command not found

我可以用这个命令修复它:

export PATH="/usr/bin:$PATH"

但是每次打开新终端时,我都会再次遇到错误,并且必须再次使用此命令。

如果您能提供帮助,我将不胜感激。顺便说一句,我使用Ubuntu 22.04.1 LTS

bashrc
  • 3 个回答
  • 389 Views
Martin Hope
MDeBusk
Asked: 2022-06-02 19:19:11 +0800 CST

~/.profile 和 ~/.bashrc 中有什么内容?

  • 26

我很难理解属于什么~/.profile和属于什么~/.bashrc。

从我读过的内容来看,在我看来~/.profile应该用于环境变量和~/.bashrc别名、函数等。如果我将我的所有export陈述从~/.bashrc移到~/.profile,一切都会按原样工作,还是我要破坏某些东西?

(如果您想查看这两个文件,这是我的 dotfiles存储库。)

编辑 2022-06-03:我已经将我的大部分环境变量从~/.bashrcto 移到~/.profile并确保自己知道~/.bash_profilesources ~/.profile. 我留下的唯一环境变量~/.bashrc是那些仅在我在 shell 中工作时才重要的环境变量,例如,与 less、提示、slrn 等有关的环境变量。一切似乎都运行良好。谢谢您的帮助。

bashrc
  • 3 个回答
  • 2756 Views
Martin Hope
Daniel
Asked: 2020-12-01 12:08:52 +0800 CST

bash.bashrc 不适用于所有用户

  • 0

因此,当我在 /etc/bash.bashrc 文件中添加该行并重新登录时,我的 PC 上有 2 个用户alias abc='echo Hello',它仅适用于第一个用户。(我更改文件的那个)我什至重新启动了我的电脑,但仍然没有工作。

这是我的 bash.bashrc 文件(我知道这不是必需的,只是为了提供更多信息):

alias abc='echo Hi' # <<< Here's the line I've added



# System-wide .bashrc file for interactive bash(1) shells.

# To enable the settings / commands in this file for login shells as well,
# this file has to be sourced in /etc/profile.

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, overwrite the one in /etc/profile)
# but only if not SUDOing and have SUDO_PS1 set; then assume smart user.
if ! [ -n "${SUDO_USER}" -a -n "${SUDO_PS1}" ]; then
  PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi

# Commented out, don't overwrite xterm -T "title" -n "icontitle" by default.
# If this is an xterm set the title to user@host:dir
#case "$TERM" in
#xterm*|rxvt*)
#    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
#    ;;
#*)
#    ;;
#esac

# enable bash completion in interactive shells
#if ! shopt -oq posix; then
#  if [ -f /usr/share/bash-completion/bash_completion ]; then
#    . /usr/share/bash-completion/bash_completion
#  elif [ -f /etc/bash_completion ]; then
#    . /etc/bash_completion
#  fi
#fi

# sudo hint
if [ ! -e "$HOME/.sudo_as_admin_successful" ] && [ ! -e "$HOME/.hushlogin" ] ; then
    case " $(groups) " in *\ admin\ *|*\ sudo\ *)
    if [ -x /usr/bin/sudo ]; then
    cat <<-EOF
    To run a command as administrator (user "root"), use "sudo <command>".
    See "man sudo_root" for details.
    
    EOF
    fi
    esac
fi

# if the command-not-found package is installed, use it
if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
    function command_not_found_handle {
            # check because c-n-f could've been removed in the meantime
                if [ -x /usr/lib/command-not-found ]; then
           /usr/lib/command-not-found -- "$1"
                   return $?
                elif [ -x /usr/share/command-not-found/command-not-found ]; then
           /usr/share/command-not-found/command-not-found -- "$1"
                   return $?
        else
           printf "%s: command not found\n" "$1" >&2
           return 127
        fi
    }
fi

我也在运行 xubuntu 18.04.5 LTS。

bash user-management bashrc alias users
  • 1 个回答
  • 906 Views
Martin Hope
steven
Asked: 2020-11-20 03:09:12 +0800 CST

如何在没有密码且不指定路径的情况下执行 sudo 命令?

  • 1

我有一个包含脚本的目录:/etc/scripts。

现在我想执行以下脚本:sudo scriptname 无需提供密码或指定脚本的路径。

我将 /etc/scripts 添加到 $PATH 变量中:

/etc/scripts:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

并且还将这些脚本的不同路径添加到我的 sudoers 文件的底部,例如:

steven ALL=(ALL) NOPASSWD:/etc/scripts/dns_add_zone,/etc/scripts/dns_add_record

所以执行脚本就像sudo /etc/scripts/scriptname工作但不是没有指定路径。

command-line bash sudo bashrc
  • 1 个回答
  • 117 Views
Martin Hope
Cholax
Asked: 2020-11-04 08:50:56 +0800 CST

Bashrc 未在 Ubuntu 20.04.1 上运行

  • 2

当我在 Ubuntu 20.04.1 上打开终端时,.bashrc 没有运行。

此外,当我使用 source 运行它时,它会抛出错误:

/usr/share/bash-completion/bash_completion:1512: parse error near `|'

并且外壳名称变得混乱:

\[\e]0;\u@\h: \w\a\]\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$

顺便说一句,我在 virtualbox 上运行 Ubuntu。刚刚安装好了。

virtualbox command-line bashrc 20.04
  • 1 个回答
  • 710 Views
Martin Hope
sam
Asked: 2020-11-01 15:11:20 +0800 CST

无法配置 CUDA 环境

  • 2

我按照此说明配置 Cuda,但这一步我尝试编写这些行

To configure the CUDA environment for all users (and applications) on your system create the file (use sudo and a text editor of your choice)

/etc/profile.d/cuda.sh

with the following content,

export PATH=$PATH:/usr/local/cuda/bin
export CUDADIR=/usr/local/cuda

但得到了"/etc/profile.d/cuda.sh" is a directory

我尝试运行 Cuda 示例并得到了

Error: target directory missing
Usage: cuda-install-samples-11.1.sh <target directory>
       Will append NVIDIA_CUDA-11.1_Samples to <target directory>

我试图在 bashrc 中编写以下内容

export CUDA_HOME=/usr/local/cuda
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64
PATH=${CUDA_HOME}/bin:${PATH} 
export PATH 

编辑

我尝试使用此命令运行示例来测试 cuda

./cuda-install-samples-11.1.sh

但得到了

Error: target directory missing
  Usage: cuda-install-samples-11.1.sh <target directory>
   Will append NVIDIA_CUDA-11.1_Samples to <target directory>

编辑 2

我试图运行这个命令

./cuda-install-samples-11.1.sh /home/user/NVIDIA_CUDA-11.1_Samples

但得到了

bash: ./cuda-install-samples-11.1.sh: No such file or directory

在此处输入图像描述

nvidia bash bashrc cuda 18.04
  • 1 个回答
  • 1694 Views
Martin Hope
elanozturk
Asked: 2020-10-30 12:23:54 +0800 CST

关于终端错误的 .bashrc 别名帮助

  • 0

我在 .bashrc 文件上有别名,例如;

alias modemreboot="IP=$(/sbin/ip route | awk '/default/ { print $3 }');echo "reboot" | sshpass -p "12345" ssh admin@$IP"

用于通过命令行重新启动我的调制解调器。当我键入或复制并粘贴到终端时,它可以工作,但是作为别名,我收到此错误;

Pseudo-terminal will not be allocated because stdin is not a terminal.
ssh: Could not resolve hostname : Name or service not known
command-line bashrc alias 20.10
  • 1 个回答
  • 93 Views
Martin Hope
Pavel V.
Asked: 2020-10-27 02:39:56 +0800 CST

我可以在不更改语言环境的情况下更改命令行输出的语言吗?

  • 1

我只想更改命令行的语言。已经有类似的 问题,但我不明白他们的答案。在~/.bashrc中,我尝试添加export LANG=en_US.UTF-8,export LC_ALL=en_US.UTF-8或echo 'export LANG=en_US.UTF-8' >>~/.bashrc,但命令行仍然使用捷克语作为我的 Ubuntu。

我错过了什么?是否需要将其插入特殊位置(现在几乎在开头)?我需要另一个命令吗?我需要在其他地方写吗?

command-line bashrc language
  • 1 个回答
  • 207 Views
Martin Hope
user1133321
Asked: 2020-10-05 21:21:43 +0800 CST

每次打开 Ubuntu 终端时都没有这样的文件或目录

  • 0

我是 ubuntu 的新手,我正在尝试添加

echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc

然后我重新加载了.bashrc

source ~/.bashrc

现在我被这个困住了 - 每次我启动终端时,我都会首先得到这个:截图 #1

bash: /catkin_ws/devel/setup.bash: No such file or directory
bash: /home/ros/Home/catkin_ws/devel/setup.bash: No such file or directory

编辑:在cat ~/.bashrc我得到以下(文件的最后几行)之后:

else 
    if [ -f "/home/ros/anaconda3/etc/profile.d/conda.sh" ]; then 
        ."/home/ros/anaconda3/etc/profile.d/conda.sh"
    else 
        export PATH="/home/ros/anaconda3/bin:$PATH" 
    fi
fi
unset __conda_setup 
# <<< conda initialize <<<

source /opt/ros/noetic/setup.bash 
source /catkin_ws/devel/setup.bash 
source ~/catkin_ws/devel/setup.bash 
source ~/catkin_ws/devel/setup.bash 
source ~/catkin_ws/devel/setup.bash 
source ~/Home/catkin_ws/devel/setup.bash 
source ~/catkin_ws/devel/setup.bash 
source ~/catkin_ws/devel/setup.bash 
source ~/catkin_ws/devel/setup.bash 

并ls ~/catkin_ws/devel给出:

cmake.lock  local_setup.bash  setup.bash      setup.zsh
env.sh      local_setup.sh    setup.sh        share
lib         local_setup.zsh   _setup_util.py

截图#2

bashrc ros
  • 1 个回答
  • 2269 Views
Martin Hope
Vegar
Asked: 2020-09-24 00:24:31 +0800 CST

Ubuntu 18.04 登录循环 .- bashrc 和 .profiles 已编辑

  • 0

当我在登录屏幕上输入密码时,屏幕会变黑几秒钟,然后返回登录屏幕。即登录循环。

我可以通过远程桌面和 SSH (puTTy) 登录。

在登录循环开始发生之前,我为 bash_rc 添加了一个别名,并为 .profile 添加了一个路径。我怀疑这是问题的原因,所以我用 etc/skel 中的文件覆盖了更改。

现在我的 .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
    fi
    ~
    ~

我的 bash rc 看起来像这样:

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
        # We have color support; assume it's compliant with Ecma-48
        # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
        color_prompt=yes
    else
        color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Add an "alert" alias for long running commands.  Use like so:
#   sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi
                       

登录腻子时,我收到错误消息:

Command 'lesspipe' is available in the following places
 * /bin/lesspipe
 * /usr/bin/lesspipe
The command could not be located because '/bin:/usr/bin' is not included in the                                                                                                                                                                              PATH environment variable.
lesspipe: command not found
Command 'dircolors' is available in '/usr/bin/dircolors'
The command could not be located because '/usr/bin' is not included in the PATH                                                                                                                                                                              environment variable.

所以我粘贴:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:$PATH

进入终端,像 ls 这样的命令再次起作用。奇怪的是,我在 tty3 或远程桌面中没有收到此错误。但是当我启动到安全模式时,我确实在 putty 和 root shell 中得到了它。这对任何人都有意义吗?

我的等/环境看起来像这样

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"

我现在花了两天时间,任何帮助和提示将不胜感激:)

我已经尝试了登录循环的典型建议解决方案:

  • XAuthority & ICEAuthority
  • 更新 NVIDIA 驱动程序
bashrc .profile
  • 1 个回答
  • 263 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve