我正在尝试自定义PS1
,以便在我进入 git 存储库时显示我所在的分支。为此,我使用了该__git_ps1
函数,一切正常。
我的问题是,根据我在互联网上搜索到的解释,你必须将文件导入git-prompt.sh
到你的.bashrc
文件中。好吧,我还没有这样做,但它仍然有效。
事实上,我尝试过locate
这样find
的脚本,但它并不存在于我的文件系统中。所以我的问题是,这样的函数在哪里定义?
我正在尝试自定义PS1
,以便在我进入 git 存储库时显示我所在的分支。为此,我使用了该__git_ps1
函数,一切正常。
我的问题是,根据我在互联网上搜索到的解释,你必须将文件导入git-prompt.sh
到你的.bashrc
文件中。好吧,我还没有这样做,但它仍然有效。
事实上,我尝试过locate
这样find
的脚本,但它并不存在于我的文件系统中。所以我的问题是,这样的函数在哪里定义?
我从 @user313992 的回答中找到了设置的默认背景颜色代码:
在类似 xterm 的终端仿真器上:
这会将背景设置为浅绿色,而无需清除屏幕:
printf %b '\e]11;#ccffcc\a'
可以。但是如何以类似的方式在 Bash shell 中设置默认前景色?例如:
printf %b '???(default_foreground_color)???'
\e]11;
并且,在哪里可以找到有关背景颜色代码和???
前景色相应代码的相关信息?
我正在 Ubuntu PC 上安装 Ros2,想确保安装步骤不会影响我的 PC。具体来说,这个命令实际上起什么作用?
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
请帮我分解一下。
我有两个网站,以后还会有更多网站,除了配置和一些其他文件外,代码相同。两个品牌的同一项目。会有更多网站 - 例如测试网站。另外,我需要更新网站的数据库结构,例如使用文件 Upd55.sql。
我用来从当前文件夹复制文件的代码:(保留权限很重要)
cp -p -R -v ./ ../web.site.pro/
我需要排除 /config/.htaccess 和其他一些文件。
我已经创建了一个组“ restricted”,并将用户“user1”添加到该组,如何限制该组访问某些指定的目录和驱动器。
我对下拉菜单的工作原理还不熟悉。它失去焦点并消失了。任务还能执行吗?还是会被中止?
我刚开始使用 Ubuntu。我希望使用一些自制的别名和环境变量,因此我做了以下操作:
将这些自制的别名放在一个initializer_file.sh
文件中,我将其放在我的个人子目录中$HOME/Teuliou/Bash_scripts/initializer_file.sh
在文件末尾添加以下几行.profile
:
# include homemade initializer file if it exists
if [ -f "$HOME/Teuliou/Bash_scripts/initializer_file.sh" ]; then
. "$HOME/Teuliou/Bash_scripts/initializer_file.sh"
fi
但这没有任何作用。当我保存文件后打开新终端时.profile
,我的别名仍然是未知命令。另一方面,我知道里面的代码initializer_file.sh
是正确的,因为如果我将其复制粘贴到终端中,别名就会起作用。我做错了什么?
我想将所有内容存储command args
在一个中array
,但它只有当所有参数都没有任何(*
)时才有效。
这是一个不使用数组的测试:
mkdir -p /tmp/hello
echo "hello" > /tmp/hello/hello.txt
echo "world" > /tmp/hello/world.txt
mkdir -p /tmp/world
# This cp command is success
cp /tmp/hello/* /tmp/world
现在将 cp 命令转换为 my_array:
mkdir -p /tmp/hello
echo "hello" > /tmp/hello/hello.txt
echo "world" > /tmp/hello/world.txt
mkdir -p /tmp/world
declare -a my_array=()
my_array[0]="cp"
my_array[1]="/tmp/hello/*"
my_array[2]="/tmp/world"
# Run the command and it will fail
"${my_array[@]}"
错误如下:
cp: cannot stat '/tmp/hello/*': No such file or directory
*
在 中可以使用 ( ) 吗?使用 实现 ' ' 的my_array
正确语法是什么?cp /tmp/hello/* /tmp/world
my_array
更新:
有一个problem
来自@choroba's answoer
,$count
和$sedond_item
将是错误的:
mkdir -p /tmp/hello
echo "hello" > /tmp/hello/hello.txt
echo "world" > /tmp/hello/world.txt
mkdir -p /tmp/world
my_array=(cp)
my_array+=(/tmp/hello/*)
my_array+=(/tmp/world)
count=${#my_array[@]}
printf "%s\n" "count is: $count"
sedond_item="${my_array[1]}"
printf "%s\n" "second item is: $sedond_item"
以下是@choroba 回答的输出:
count is: 4
second item is: /tmp/hello/hello.txt
但在我的原始数组中$count
和是正确的:$sedond_item
mkdir -p /tmp/hello
echo "hello" > /tmp/hello/hello.txt
echo "world" > /tmp/hello/world.txt
mkdir -p /tmp/world
declare -a my_array=()
my_array[0]="cp"
my_array[1]="/tmp/hello/*"
my_array[2]="/tmp/world"
count=${#my_array[@]}
printf "%s\n" "count is: $count"
sedond_item="${my_array[1]}"
printf "%s\n" "second item is: $sedond_item"
这是原始数组的输出:
count is: 3
second item is: /tmp/hello/*
我想列出所有以字母lc-开头的服务。然后我想重新启动它们。
我该如何附加此内容?我在想类似的事情:
systemctl -l | grep ?? | systemctl restart ???
我使用传输远程终端命令,并且想使用 bash 脚本在其他计算机上重新创建我的 torrent 文件的当前状态。
我想创建一个 bash 脚本,列出我当前状态 transmission-remote 的所有磁力链接/URL。这样可以轻松保存这些链接,并在需要时在另一台机器上重新创建我的种子状态。
transmission-remote -l 等命令仅列出种子的名称和元数据,但这不足以重新创建我现在的状态。此外,每次我向 transmission 添加新链接时,都会迫使我手动将这些链接保存在某个文本文件中。
有什么想法吗? transmission-remote 中有一个命令,它提供了磁力链接/URL 信息。