如何设置和使用 shell 变量?

如何设置和使用 shell 变量?
IRSTLM=$HOME/irstlm

我需要帮助来设置这个变量。想知道这是否是正确的语法

IRSTLM=/home/user/irstlm

可以从 root 运行吗?我需要在 root 中执行此操作才能访问某些文件,如果您想查看其使用的上下文,我还可以添加我尝试运行的其余命令。

新问题,不知道为什么,但这不应该输出扩展名为 .arpa 的文件吗?我似乎没有得到那个文件,我需要它运行下一个命令来完成编译这个程序。

~/irstlm/bin/add-start-end.sh  < ~/corpus/news-commentary-v7.fr-en.true.en > news-commentary-v7.fr-en.sb.en export IRSTLM=$HOME/irstlm; ~/irstlm/bin/build-lm.sh -i  news-commentary-v7.fr-en.sb.en  -t ./tmp  -p -s improved-kneser-ney -o news-commentary-v7.fr-en.lm.en 

以下是完整命令:

/home/user/irstlm/bin/add-start-end.sh  < /home/user/corpus/news-commentary-v7.fr-en.true.en > news-commentary-v7.fr-en.sb.en export IRSTLM=$HOME/irstlm; /home/user/irstlm/bin/build-lm.sh -i  news-commentary-v7.fr-en.sb.en  -t ./tmp  -p  -s improved-kneser-ney -o news-commentary-v7.fr-en.lm.en 

答案1

如果它是一个一次性命令,那么最好只为该命令进行设置,即:

IRSTLM=/home/user/irstlm /home/user/irstlm/bin/add-start-end.sh  \
  < /home/user/corpus/news-commentary-v7.fr-en.true.en > news-commentary-v7.fr-en.sb

如果它是脚本的一部分,请使用:

export IRSTLM=/home/user/irstlm
/home/user/irstlm/bin/add-start-end.sh < /home/user/corpus/news-commentary-v7.fr-en.true.en > news-commentary-v7.fr-en.sb

答案2

我明白了,谢谢你的建议,它们确实有帮助,这是我运行的最后一个命令,似乎我没有正确地将变量设置为“irstlm=/root/irstlm”最后一个命令:

 /root/irstlm/bin/add-start-end.sh < /home/user/corpus/news-commentary-v7.fr-en.true.en> news-commentary-v7.fr-en.sb.enexport IRSTLM=$HOME/irstlm; /root/irstlm/bin/build-lm.sh -i news-commentary-v7.fr-en.sb.en -t ./tmp -p -s improved-kneser-ney -o news-commentary-v7.fr-en.lm.en 

相关内容