“sed”命令的奇怪问题

时间:2015-04-23 06:15:36

标签: linux command-line terminal

在我的脚本中,这个 - 由于某种原因未知 - 在达到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
}

1 个答案:

答案 0 :(得分:1)

替换" {hash}"使用" $ {hash}"