I have a script, where there is a line:
eval for i in \{"$1".."$2"\}\; do [ ! -e "$3"/\$i.\* ] \&\& echo \"\$i\" \; done \| shuf \| mycommand "$3"
which means: first create a sequence of numbers where no files named after the numbers exist, pipe them to shuf
, and then pipe them to mycommand
which is an ELF executable.
Most of time the script runs fine, but sometimes it gets segment fault error, i.e. The segment fault error is not reproducible.
$ myscript 0001 734 XMJ
/home/tim/bin/myscript: line 25: 10170 Exit 1 for i in {0001..734};
do
[ ! -e XMJ/$i.* ] && echo "$i";
done
10171 Done | shuf
10172 Segmentation fault (core dumped) | mycommand XMJ
Does that mean that the segment fault is raised when running shuf
?
What can we deduce from the error message and possibly correct it?
Thanks.
eval
. Tryfor i in $(seq "$1" "$2"); do...
and trade an external process for readability. – Chris Davies Oct 29 '18 at 21:43seq -w
for those leading zeroes (and seq would be the external process, vs. {x..y} being done by bash itself) – frostschutz Oct 29 '18 at 21:47i="$1"; while [[ $i -le "$2" ]]... ((i++))
and still avoid that horribleeval
. – Chris Davies Oct 29 '18 at 22:02