我正在使用 OHMYZSH,但我正在考虑构建 Zsh 的最小配置。
\n所以这就是问题所在。Ohmyzsh 有特殊的完成行为。例如:如果我在主目录中键入并cd mus点击 TAB cd Music,即使我用小写字母键入句子,它也会扩展为 。
我已经创立了这个:
\n让 zsh 返回不区分大小写的自动完成匹配,但更喜欢精确匹配
\n这是我的问题,但恰恰相反。我想case insensitive在不安装 OHMYZSH 的情况下获得。
查看 OHMYZSH 结构,我发现了这一点:
\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ./cache
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ./CODE_OF_CONDUCT.md
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ./CONTRIBUTING.md
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ./自定义
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ./lib
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ./LICENSE.txt
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ./log
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ./oh-my-zsh.sh
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ./plugins
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ./README.md
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ./模板
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ./主题
\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 ./工具
\n8个目录,5个文件
\nlib文件夹内有一些配置文件。
\n库
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 bzr.zsh …
我正在尝试使用两因素身份验证将图像推送到 gitlab 注册表。它给了我这个错误消息:
unauthorized: HTTP Basic: Access denied\nYou must use a personal access token with 'api' scope for Git over HTTP
Run Code Online (Sandbox Code Playgroud)
我尝试使用此命令登录,但它仍然显示访问被拒绝:
docker login https://registry.gitlab.com/my_registry -u my_user_name -p my_public_key
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?如何使用公钥推送和拉取图像?
如何将包含空格的变量传递给脚本以便脚本正确处理它们?
我的最小例子:
测试文件
#!/bin/bash
COUNTER=1
for i in "$@"; do echo "$COUNTER '$i'"; ((COUNTER++)); done
Run Code Online (Sandbox Code Playgroud)
如果我直接使用一些参数(转义空间)调用脚本,它会起作用:
./test.sh 1 2 3\ 4 5
Run Code Online (Sandbox Code Playgroud)
输出(如预期):
1 '1'
2 '2'
3 '3 4'
4 '5'
Run Code Online (Sandbox Code Playgroud)
如果我将参数存储到变量中,反斜杠将不再被正确解释为转义字符。
TEST_ARGS="1 2 3\ 4 5"
./test.sh $TEST_ARGS
Run Code Online (Sandbox Code Playgroud)
输出:
1 '1'
2 '2'
3 '3\'
4 '4'
5 '5'
Run Code Online (Sandbox Code Playgroud)
我想得到像以前一样的输出。我怎样才能达到它?
TEST_ARGS="1 2 3\ 4 5"
# how to call ./test.sh here?
Run Code Online (Sandbox Code Playgroud)
我更详细的用例是,我有一些脚本,它为我的其他工具/脚本准备所有标志。
prepare_flags.sh(非常简约):
#!/bin/bash
echo 'TEST_ARGS="1 2 3\ 4 5"'
Run Code Online (Sandbox Code Playgroud)
在我的实际脚本中,我获取了prepare_flags.sh脚本的输出以访问TEST_ARGS:
source <( ./prepare_flags.sh )
./test.sh $TEST_ARGS # …Run Code Online (Sandbox Code Playgroud) ascii() {printf '%d' "'$1"}
Run Code Online (Sandbox Code Playgroud)
我目前正在使用此函数将字符转换为 ASCII,但是我只想将函数的结果存储为变量而不打印 ascii。我该怎么办呢?(请记住,我总共只使用了几个小时的 bash,如果这是一个愚蠢的问题,我很抱歉。)
.js我正在尝试通过 PowerShell 命令行创建 JavaScript文件,但是,当我尝试 echo 时,该文件在创建后立即消失。PowerShell 中是否有与 BASH 命令相同的命令$ touch?
我试图了解参数扩展在 bash 脚本中的作用。
第三方bash脚本
#!/bin/sh
files="${*:--}"
# For my understanding I tried to print the contents of files
echo $files
pkill bb_stream
if [ "x$VERBOSE" != "" ]; then
ARGS=-v1
fi
while [ 1 ]; do cat $files; done | bb_stream $ARGS
Run Code Online (Sandbox Code Playgroud)
当我运行时./third_party_bash_script,它打印的只是一个连字符-,没有其他内容。由于它对我来说没有意义,我也尝试在终端中进行实验
$ set one="1" two="2" three="3"
$ files="${*:--}"
$ echo $files
one="1" two="2" three="3"
$ set four="4"
$ files="${*:--}"
four="4"
Run Code Online (Sandbox Code Playgroud)
我似乎无法理解它在做什么。有人可以帮助我解释${*:--}by thesh吗?
我的 MacBook Air 配备了 macOS Mojave 版本 10.14.6。即使我检查了brew版本,我也无法安装wget。
brew --version
Run Code Online (Sandbox Code Playgroud)
输出是:
Homebrew 3.3.13
Homebrew/homebrew-core (no Git repository)
Homebrew/homebrew-cask (git revision fb6ec06d8b; last commit 2022-01-31)
Run Code Online (Sandbox Code Playgroud)
当我尝试安装 wget 时:
brew install wget
Run Code Online (Sandbox Code Playgroud)
这是结果:
Warning: No available formula with the name "ca-certificates".
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Running `brew update --preinstall`...
Error: No formulae …Run Code Online (Sandbox Code Playgroud) 我尝试使用 bash 运行以下脚本:
#!/bin/bash
myvar="data1"
data='[
{
"resource_name": "data1.something",
"resource_type": "Topic"
},
{
"resource_name": "data2.something",
"resource_type": "Topic"
}
]'
query=$(echo ".[] | select((.resource_type==\"Topic\") and (.resource_name | startswith(\"${myvar}\") | not))")
echo ${data} | jq ${query}
Run Code Online (Sandbox Code Playgroud)
它不起作用,因为行:
echo ${data} | jq ${query}
Run Code Online (Sandbox Code Playgroud)
但如果我在 zsh 中运行相同的脚本,它就会起作用。并给我以下错误:
jq: error: Could not open file |: No such file or directory
jq: error: Could not open file select((.resource_type=="Topic"): No such file or directory
jq: error: Could not open file and: No such file or directory
jq: …Run Code Online (Sandbox Code Playgroud) 我想在使用 dotnetpublish 时在命令行中命名环境。我找到了这个解决方案
dotnet publish -o site /p:EnvironmentName=Production
Run Code Online (Sandbox Code Playgroud)
我以前从未见过 /p: 参数,想知道它到底是什么。我试图用谷歌搜索它,但由于它的语法,很难找到任何东西。
我特别想知道我是否也可以在 Linux 机器上的 bash 中使用这个命令。
有没有办法在使用 sed 找到匹配项后替换以下两行?
我有一个文件
#ABC
oneSize=bar
twoSize=bar
threeSize=foo
Run Code Online (Sandbox Code Playgroud)
但我想在模式#ABC匹配后替换两行直接的行,以便它变成
#ABC
oneSize=foo
twoSize=foo
threeSize=foo
Run Code Online (Sandbox Code Playgroud)
我能做到
gsed '/^#ABC/{n;s/Size=bar/Size=foo/}' file
但它只是改变了线路twoSize而不是oneSize
有没有办法让它同时改变 oneSize 和 TwoSize