gpt4 book ai didi

linux - 将命令行参数传递给 .sh (shell) 文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:37:16 28 4
gpt4 key购买 nike

我正在终端中执行这样的 shell 文件:

./cherrypicker.sh input.txt

input.txt 包含输入文本。

我的目的是将 input text 作为 web 界面的命令行参数直接传递

我检查了 cherrypicker.sh 文件,以获得一些线索。它有

tools/pos/pos.sh tools/pos $1 > $1.pos 2> /dev/null

如果 $1 是来自 input.txt 的文本,那么我可以直接传递文本。但是当我执行 echo $1 时,它会给出 input.txt

我无法理解 > 以及 2/dev/null 表示什么

任何解释都会非常有用。我检查了 .sh 文件,但文章说它是等同于 .bat 文件的 shell 文件

Cherrypicker.sh

#!/bin/bash

echo "running stanford pos tagger..."
tools/pos/pos.sh tools/pos $1 > $1.pos 2> /dev/null

echo $1.pos

echo "running stanford ner tagger..."
tools/ner/ner.sh tools/ner $1 > $1.ner 2> /dev/null

echo "running charniak parsing..."
java MakeCharniakInput $1
tools/charniak-parser/PARSE/parseIt -l300 tools/charniak-parser/DATA/EN/ $1.charniakIN > $1.charniak

echo "running minipar parsing..."
tools/minipar/pdemo/pdemo -p tools/minipar/data/ < $1 > $1.minipar

echo "detecting mentions..."
java MentionDetection $1
tools/crf++/crf_test -m modelmd $1.crf > $1.pred
java CreateNPSpan $1 $1.pred


# if [[ $1 = "mp" ]]
# then
# echo "creating feature file...."
# java -cp .:edu.mit.jwi.jar CherryPick mp raw.txt
# echo "classifying clusters using $1 model....."
# tools/svmmentionpair/svm_classify raw.txt.mpsvm modelmp raw.txt.mppred
# java MakeCluster raw.txt raw.txt.mppred
# elif [[ ( $1 = "mr" ) || ( $1 = "cr" ) ]]
# then
echo "creating feature file...."
java -cp .:edu.mit.jwi.jar CherryPick cr $1
echo "classifying clusters using cr joint model....."
tools/svmrank/svm_classify $1 modelrank > $1.entities
# else
# echo "cannot classify clusters using *mysterious* model....."
# fi


echo "creating output....."
java MakeResponse $1

最佳答案

命令:

   tools/pos/pos.sh tools/pos $1 > $1.pos 2> /dev/null

解释:

tools/pos/pos.sh  - script

tools/pos - Positional argument 1 for pos.sh

$1 - Positional argument 2 for pos.sh

$1.pos - Is a file which will hold the standard output of pos.sh

/dev/null - is a null file which will hold standard error

在这种情况下,tools/pos/pos.sh 采用两个位置参数 tools/pos & $1(input.txt) 完成它的工作

并将tools/pos/pos.sh的标准输出重定向到文件$1.pos(input.txt.pos)> $1部分命令的 .pos

上述命令的2>/dev/null部分将标准错误重定向到/dev/null

关于linux - 将命令行参数传递给 .sh (shell) 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25905798/

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