gpt4 book ai didi

bash - unix shell 脚本 - jot -r 1 1 4 是什么意思?我可以用 seq 替换 jot 吗?

转载 作者:行者123 更新时间:2023-12-04 18:57:08 25 4
gpt4 key购买 nike

我是 unix 和 shell 脚本的新手。
我正在编写一个脚本,将训练和测试图像文件名写入两个列表:

train.list
test.list

COUNT=-1
for folder in $1/*
do
COUNT=$[$COUNT + 1]
for imagesFolder in "$folder"/*
do
if (( $(jot -r 1 1 $2) > 1 )); then
echo "$imagesFolder" $COUNT >> train.list
else
echo "$imagesFolder" $COUNT >> test.list
fi
done
done
我得到了错误:

/convert_images_to_list.sh: line 31: jot: command not found

./convert_images_to_list.sh: line 31: ((: > 1 : syntax error: operand expected (error token is "> 1 ")


我试图改变 jotseq错误是:

eq: invalid option -- 'r'

./convert_images_to_list.sh: line 31: ((: > 1 : syntax error: operand expected (error token is "> 1 ")


我还检查了 'seq --help'上面写着 seq [OPTION]... FIRST INCREMENT LAST . jot -r 1 1 &2 是什么意思替换为,如果我想使用 seq而不是 jot .
非常感谢。

最佳答案

你可能不需要jotseq ;您只是想生成一个介于 1 和 $2 之间的随机整数.只要$2不是太大,你也不是很担心使用均匀分布,你可以用

# $RANDOM yields a value between 0 and 32767
# Thus, $RANDOM % $2 yields a value between 0 and $2 - 1
if (( $RANDOM % $2 > 0 )); then
...

关于bash - unix shell 脚本 - jot -r 1 1 4 是什么意思?我可以用 seq 替换 jot 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59344512/

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