跳转到内容
新建笔记

我写的脚本

  • 1
#!/bin/bash
# 定义您想要迭代的 epoch 值
epochs=("69" "74" "79" "84" "89" "94" "99" "104" "109" "114" "119" "124" "129" "134" "139" "144" "149" "154" "159" "164" "174" "179" "184" "189" "194" "199" "204" "209" "214" "219" "224" "229" "234" "239" )
# 指向 run.py 脚本的路径
run_script="run.py"
# 指定输出文件名
output_file="mycleanduck.log"
# 删除旧的输出文件,以防之前的运行结果影响
rm -f $output_file
# 循环遍历每个 epoch 并执行命令
for epoch in "${epochs[@]}"; do
echo "正在运行 epoch:$epoch"
# 修改 cfg.test.epoch 的值
sed -i "s/cfg\.test\.epoch = .*/cfg.test.epoch = $epoch/" lib/config/config.py
# 执行 run.py 脚本,并将输出追加到文件中
python $run_script --type evaluate --cfg_file configs/linemod.yaml test.dataset LinemodOccTest model mycleanduck cls_type duck >> $output_file
done
# 循环结束后,将 cfg.test.epoch 恢复为原始值
sed -i "s/cfg\.test\.epoch = .*/cfg.test.epoch = 169/" lib/config/config.py
  • 2
#!/bin/bash
echo "Input filename"
read name
echo "The input name is $name"
echo "Create $naem file"
mkdir $name
echo "Done"
echo "Move lm into $name"
mv lm $name
echo "Done"
echo "Move olm into $name"
mv olm $name
echo "Done \n"
echo "Zip $name"
zip $name.zip $name -r
echo "Done"
echo "New create lm olm file"
mkdir lm olm
echo "Done"

在 Bash 脚本中,$(command) 是命令替换的语法,它允许你将命令的输出赋值给变量或在其他命令中使用。

当你使用 $(pwd),实际上是执行 pwd 命令,并将其输出(即当前工作目录)捕获到变量中。

例如:

终端窗口
current_dir=$(pwd)

在这里,$(pwd) 会被替换为 pwd 命令的输出,然后这个输出值被赋给 current_dir 变量。

所以,答案是:当你想要捕获并使用命令的输出时,你需要使用 $()。但对于普通的变量,你不需要使用 $(),只需要在变量名前加 $ 就可以了。例如,$current_dir 会给出你之前存储在 current_dir 变量中的值。