gpt4 book ai didi

linux - "sed"命令的奇怪问题

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:52:35 26 4
gpt4 key购买 nike

在我的脚本中,由于未知原因,当它到达 sed 命令时给我错误:

function nzb() {
( [ -z "$1" ] ) && echo "No argument is given!" && return 1
hash="$(echo -n "$1" | md5sum | cut -d" " -f1)"
mkdir "${hash}" && rar a -m0 -v200M "${hash}"/"${hash}".rar "$1" && rm -rf "$1" &&
par2 c -r10 -l "${hash}"/"${hash}".par2 "${hash}"/* && ~/newsmangler-master/mangler.py
-c ~/.newsmangler.conf "{hash}" && sed -i "1i$1\n${hash}\n" ~/hashs.txt
}

.

ERROR: "{hash}" does not exist or is not a file!
ERROR: no valid arguments provided on command line!

但是当我——出于好奇——删除了 sed 的前面的命令时,它的工作就像它假设的那样完美:

function nzb() {
( [ -z "$1" ] ) && echo "No argument is given!" && return 1
hash="$(echo -n "$1" | md5sum | cut -d" " -f1)"
sed -i "1i$1\n${hash}\n" ~/hashs.txt
}

.

有什么想法吗?

编辑: 问题似乎出在这个区域:

 . . . && ~/newsmangler-master/mangler.py -c ~/.newsmangler.conf "{hash}" && . . .

因为即使这样也行得通:

function nzb() {
( [ -z "$1" ] ) && echo "No argument is given!" && return 1
hash="$(echo -n "$1" | md5sum | cut -d" " -f1)"
mkdir "${hash}" && rar a -m0 -v200M "${hash}"/"${hash}".rar "$1" && rm -rf "$1" &&
par2 c -r10 -l "${hash}"/"${hash}".par2 "${hash}"/* && sed -i "1i$1\n${hash}\n"
~/hashs.txt
}

最佳答案

用“${hash}”替换“{hash}”

关于linux - "sed"命令的奇怪问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29815197/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com