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};
    [ ! -e XMJ/$i.* ] && echo "$i";
     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?


  • 3
    That's a horrible use of eval. Try for i in $(seq "$1" "$2"); do... and trade an external process for readability. – roaima Oct 29 '18 at 21:43
  • Thanks. What do you mean by "trade an external process "? Can you be more specific of how to write the script without eval? – Tim Oct 29 '18 at 21:43
  • you need seq -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:47
  • 1
    @glennjackman then i="$1"; while [[ $i -le "$2" ]]... ((i++)) and still avoid that horrible eval. – roaima Oct 29 '18 at 22:02
  • 1
    If the message says “(core dumped)” then core really was dumped. – Stephen Kitt Oct 29 '18 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.