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
    • 最新
    • 标签
主页 / unix / 问题

问题[prompt](unix)

Martin Hope
Enzo Basile
Asked: 2022-06-22 02:00:31 +0800 CST

在终端 Linux 中设置名称

  • 4

我的问题很愚蠢,但在互联网上找不到任何解释我的方法。问题是我想让终端中的名称显示为:Server mpi@raspberry: ... $但找不到如何将“名称”服务器添加到用户(我正在调用该名称,但可能不正确)。相反,我的终端显示mpi@raspberry: ... $

bash prompt
  • 2 个回答
  • 175 Views
Martin Hope
Joshua Crotts
Asked: 2022-04-26 12:08:48 +0800 CST

是否可以在 shell 提示符下输出 LaTeX?

  • -1

有几个“lambda”提示符(即使用$\lambda$ 符号的shell 提示符)。虽然这些在理论上看起来不错,但许多字体不使用我喜欢的 lambda 符号:$\lambdaup$。我不确定是否可以将已编译的 LaTeX 嵌入到 shell 提示符中,例如fish、zsh ......但如果是的话,谁能告诉我怎么做?

结果发现 Unix 堆栈交换不会呈现 LaTeX,但简单的 Google 搜索将显示我的意思。

shell prompt
  • 2 个回答
  • 46 Views
Martin Hope
Rafal Niznik
Asked: 2022-04-25 07:07:47 +0800 CST

Ansible:如何验证 ansible_become_user,以及是否缺少用户输入提示(多个主机)

  • 1

我使用多个主机,如果清单或剧本中未设置 ansible_become_user 和 ansible_become_password,我想提示用户提供 sudo 用户名和密码

我使用以下内容:

库存文件:

os:
  children:
    centos:
      hosts:
        clean_centos_1:
          vars:
          ansible_become_user: root
          ansible_become_password: root
    rocky:
      hosts:
        clean_rocky_1:
    ubuntu:
      hosts:
        clean_ubuntu_1:
    debian:
      hosts:
        clean_debian_1:
    alpine:
      hosts:
        clean_alpine_1:
          vars:
          ansible_become_user: root
          ansible_become_password: root
  vars:
    ansible_user: test 
    ansible_password: test

剧本

- name: "PLAY1"
  hosts: all
  gather_facts: no

  tasks:
## Identify ansible_become_user if present
#------------------------------------------------------
  - name: "Test if ansible_become_user is empty" 
    debug:
      var: ansible_become_user
    register: result
    when: ansible_become_user | length > 0
    ignore_errors: yes

  - name: "Set status_ansible_become_user"
    set_fact:
      status_ansible_become_user: "{{ status_ansible_become_user|default({}) | combine( { ansible_host: 'absent' if result.failed is true else 'present' }) }}"


## Get user input
#------------------------------------------------------
  - name: "User-input: <ansible_become_user>"
    pause:
      prompt: "\nEnter root username or sudo username for host: {{ansible_host}}"
    when: item == 'absent'
    loop: "{{status_ansible_become_user.values()}}"

  - set_fact:
      ansible_become_user: "{{ result.user_input }}"
    when: result.failed is false


  - debug:
      var: item == 'absent'
    loop: "{{status_ansible_become_user.values()}}"

上例中因为 clean_centos_1 排在第一位,并且设置了 ansible_become_user 和 ansible_become_passwor,其他主机如下跳过,没有提示

TASK [User-input: <ansible_become_user>] **********************************************************************************************************************************************************************************************************************************
skipping: [clean_centos_1] => (item=present)

TASK [set_fact] ***********************************************************************************************************************************************************************************************************************************************************
fatal: [clean_centos_1]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'user_input'\n\nThe error appears to be in '/git/ansible/role/rar.pkg.python/playbook/test.yml': line 28, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n  - set_fact:\n    ^ here\n"}
skipping: [clean_rocky_1]
skipping: [clean_debian_1]
skipping: [clean_ubuntu_1]
fatal: [clean_alpine_1]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'user_input'\n\nThe error appears to be in '/git/ansible/role/rar.pkg.python/playbook/test.yml': line 28, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n  - set_fact:\n    ^ here\n"}


问题:
如何正确验证是否设置了 ansible_become_user 和 ansible_become_password,如果未设置,如何提示使用以提供每个主机可能不同的 ansible_become_user 和 ansible_become_password?

ansible prompt
  • 1 个回答
  • 184 Views
Martin Hope
Enlico
Asked: 2022-04-02 00:03:43 +0800 CST

为什么提示显示在终端的顶部,而不是底部?

  • 1

我为什么要问这个?

你可以猜到,这主要是出于好奇。但是,为什么我的脑海里会涌现出好奇心呢?

好吧,有一段时间我注意到我很不高兴,在我跑去clear清理终端屏幕之后,我不得不把眼睛从屏幕底部移开,在连续命令和他们的命令之后提示结束了输出,到屏幕的顶部。

那是我将其插入我的~/.bashrc:

__prompt_to_bottom_line() {
  tput cup $LINES
}
alias clear='clear && __prompt_to_bottom_line'

对我来说,运行后提示在底部clear意味着提示总是在底部,从不在顶部。其他一切都和平常一样。

其他人呢?

我想我不是唯一一个感到这种必要性的人。以这个问题为例:用户希望提示始终位于顶部,输出位于其下方,但顺序相反(但一个命令的一个输出,即使是多行,也不会颠倒,很明显)。

如果您考虑一下,该用户希望在屏幕上看到tac的正是我所期望的(除了多行输出没有反转)。

所以我的问题是

为什么终端设计有这种不统一的行为?我所说的非均匀是指它从一种除非一个 s 否则永远不会重复的情况开始,这将在clear命令后更改命令,提示在屏幕下方移动,最终提示最终处于“稳定”位置屏幕底部,它不会再从那里移动,除非一个clears.

输出向下/向上推总是在顶部/底部的线不是更适合眼睛的设计吗?

shell prompt
  • 1 个回答
  • 168 Views
Martin Hope
pernia
Asked: 2020-03-05 16:57:26 +0800 CST

是否可以让 mksh 在 PS1 中使用代字号(~)作为 home ?

  • 1

例如,不是user@hostname:/home/user按照手册页中的示例在提示中显示,可以让 mksh 显示user@hostname:~吗?

linux prompt
  • 1 个回答
  • 443 Views
Martin Hope
Subi
Asked: 2020-01-26 03:04:32 +0800 CST

bash 提示符中的多余字符

  • 0

我一直在尝试自定义我的 bash 提示符

下面是我的配置

#!bin/bash
Nocolor="\[\033[0m\]"       # Text Reset

# Bold High Intensty
BIBlack="\[\033[1;90m\]"      # Black
BIRed="\[\033[1;91m\]"        # Red
BIGreen="\[\033[1;92m\]"      # Green
BIYellow="\[\033[1;93m\]"     # Yellow
BIBlue="\[\033[1;94m\]"       # Blue
BIPurple="\[\033[1;95m\]"     # Purple
BICyan="\[\033[1;96m\]"       # Cyan
BIWhite="\[\033[1;97m\]"      # White

function git_color {
  local git_status="$(git status 2> /dev/null)"

  if [[ $git_status =~ "Changes not staged for commit" ]]; then
    echo -e $BIRed
  elif [[ $git_status =~ "Changes to be committed" ]]; then
    echo -e $BIYellow
  else
    echo -e $BIGreen
  fi  
}

PS1="\u\[$BIRed\]\W"
PS1+="\$(git_color) $ " 
PS1+="\[$Nocolor\]"

export PS1

我要做的是根据我的 git 状态用特定颜色突出显示我的 $ 符号

在这些之后,我的提示看起来像这样 在此处输入图像描述

这\[\]来自哪里。我尝试了所有可能的方法来调用方法 git_status 但没有任何效果。

我的 Bash 版本

bash --version
GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

帮帮我。提前致谢。

bash prompt
  • 2 个回答
  • 107 Views
Martin Hope
Rajan
Asked: 2019-11-29 20:23:32 +0800 CST

显示的不是用户名 bash-4.2$。我该如何解决?

  • 1

在 Linux 中通过 SSH 命令连接到服务器后ssh: IP address。在我的服务器终端更改为bash-4.2$.

如果我尝试从 Windows 中的 Putty 连接,它会连接但会显示此内容-bash: /etc/profile: Permission denied,并且终端会打开bash-4.2$而不是用户名。

bash prompt
  • 2 个回答
  • 5017 Views
Martin Hope
vorant
Asked: 2019-09-05 03:37:18 +0800 CST

如何将插入符号移动到行尾

  • -1

我想向终端添加颜色和 git 分支名称。我添加了 PS1.bashrc 在此处输入图像描述 但有问题

在没有 git 的文件夹中,一切正常,但是 git 插入符号的位置转到行的开头以及初始字符串上方的所有新文本类型 在此处输入图像描述

它已经保存在 LF 行分隔符中

bash prompt
  • 1 个回答
  • 99 Views
Martin Hope
Luciano
Asked: 2019-08-28 09:26:33 +0800 CST

无法在 Gnome 终端 v3.28.1 中更改 PS1 值(带有 Cinnamon 的 Linux Mint 19.2)

  • 1

我无法使用 Cinnamon 更改 Linux Mint 19.2终端模拟器的 de PS1 提示值。它仅适用于在控制台上进行的登录(F1 到 F6)。

文件的最后几行.profile:

export PS1='my-customized-prompt $'
export PSCOPY=$PS1

重新启动 Cinnamon 后(我也尝试过重新启动计算机): 在 之后,似乎还有其他东西.profile正在更改PS1值,例如终端模拟器或任何其他 bash“功能”。

luc@lucmint:~$ echo $PSCOPY
my-customized-prompt $
luc@lucmint:~$ echo $PS1
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$
luc@lucmint:~$ 

但是,当我使用“-l”参数从命令行运行 bash 或使用su 命令更改用户时,它可以工作:

luc@lucmint:~$ bash -l
my-customized-prompt $logout
luc@lucmint:~$ su - luc
Password: 
my-customized-prompt $

这是怎么回事?当终端仿真器打开时,谁在覆盖 PS1 变量?以及如何预防?

编辑:

主目录中的所有隐藏文件:

$ ls -ld  ~/.*
drwxr-xr-x 30 luc  luc   4096 Aug 27 14:44 /home/luc/.
drwxr-xr-x  3 root root  4096 Aug 26 14:27 /home/luc/..
-rw-------  1 luc  luc   4706 Aug 27 14:42 /home/luc/.bash_history
-rw-r--r--  1 luc  luc    220 Aug 26 14:27 /home/luc/.bash_logout
-rw-r--r--  1 luc  luc   3771 Aug 27 14:00 /home/luc/.bashrc
drwx------ 10 luc  luc   4096 Aug 26 16:36 /home/luc/.cache
drwxrwxr-x  4 luc  luc   4096 Aug 26 15:25 /home/luc/.cinnamon
drwxr-xr-x 14 luc  luc   4096 Aug 26 16:36 /home/luc/.config
-rw-r--r--  1 luc  luc     27 Aug 26 14:36 /home/luc/.dmrc
drwx------  2 luc  luc   4096 Aug 26 14:36 /home/luc/.gconf
-rw-r--r--  1 luc  luc    112 Aug 26 18:06 /home/luc/.gitconfig
drwx------  3 luc  luc   4096 Aug 26 16:36 /home/luc/.gnome
drwx------  3 luc  luc   4096 Aug 26 14:36 /home/luc/.gnupg
-rw-r--r--  1 luc  luc    245 Aug 26 18:18 /home/luc/.gtkrc-2.0
-rw-r--r--  1 luc  luc    516 Aug 26 14:27 /home/luc/.gtkrc-xfce
-rw-------  1 luc  luc   5470 Aug 27 14:43 /home/luc/.ICEauthority
drwxrwxr-x  2 luc  luc   4096 Aug 26 16:33 /home/luc/.icons
drwxr-xr-x  4 luc  luc   4096 Aug 26 17:53 /home/luc/.java
-rw-------  1 luc  luc     32 Aug 27 14:20 /home/luc/.lesshst
drwx------  3 luc  luc   4096 Aug 26 14:36 /home/luc/.local
drwx------  5 luc  luc   4096 Aug 26 15:04 /home/luc/.mozilla
drwxr-xr-x  7 luc  luc   4096 Aug 26 15:49 /home/luc/.nbi
drwxr-xr-x  3 luc  luc   4096 Aug 26 15:54 /home/luc/.netbeans
drwx------  3 luc  luc   4096 Aug 26 16:36 /home/luc/.pki
-rw-r--r--  1 luc  luc    938 Aug 27 14:44 /home/luc/.profile
drwx------  2 luc  luc   4096 Aug 26 16:49 /home/luc/.ssh
-rw-r--r--  1 luc  luc      0 Aug 26 14:40 /home/luc/.sudo_as_admin_successful
drwxrwxr-x  3 luc  luc   4096 Aug 26 18:19 /home/luc/.themes
-rw-r-----  1 luc  luc      5 Aug 27 14:43 /home/luc/.vboxclient-clipboard.pid
-rw-r-----  1 luc  luc      5 Aug 27 14:43 /home/luc/.vboxclient-display.pid
-rw-r-----  1 luc  luc      5 Aug 27 14:43 /home/luc/.vboxclient-draganddrop.pid
-rw-r-----  1 luc  luc      5 Aug 27 14:43 /home/luc/.vboxclient-seamless.pid
-rw-------  1 luc  luc   8268 Aug 27 14:44 /home/luc/.viminfo
-rw-------  1 luc  luc     52 Aug 27 14:43 /home/luc/.Xauthority
-rw-rw-r--  1 luc  luc    131 Aug 26 18:28 /home/luc/.xinputrc
-rw-------  1 luc  luc  19039 Aug 27 14:44 /home/luc/.xsession-errors
-rw-------  1 luc  luc  97892 Aug 27 14:42 /home/luc/.xsession-errors.old
bash prompt
  • 1 个回答
  • 634 Views
Martin Hope
elekgeek
Asked: 2019-08-02 02:49:52 +0800 CST

除了命令及其输出之外,还将 bash 提示符和命令打印到输出中

  • -1

我正在寻找一种将 bash 提示符、命令及其输出打印到图像中的方法,如下所示,以便在学习时进行文档记录,我编写了一个快速命令来执行此操作,但我需要自动打印 bash 提示符而不是我当用户或路径更改时更改命令的这一部分[$USER@`hostname` ~]#,不要忘记主目录的波浪号和 #/$ 取决于用户是否是 root 以便我需要更改的是cmd="ls -l";,我也不想使用$PWD 因为我得到了完整的路径,而不是我需要确切的 bash 提示符:

cmd="ls -l"; convert -font DejaVu-Sans-Mono-Book -pointsize 16 label:"$(echo "[$USER@`hostname` ~]# $cmd\n";$cmd)" /home/myuser/Desktop/result.png

上面的结果就是这个镜像,注意[root@centos7 ~] 也包含在镜像中:

在此处输入图像描述

我从这个答案和这个答案中尝试了变量 $PS1 ,但我得到:

[\u@\h \W]\$

谢谢

bash prompt
  • 1 个回答
  • 748 Views

Sidebar

Stats

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

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve