2

I'm getting a segmentation fault with the following script when it's more that one child dir past the pwd. The program kills with the error message and I have to reset the shell.

For example: I start in / and run the script. I navigate to from / to /etc just fine. When I try to go to /etc/httpd/ that's when I get the segment fault.

Another example: I start the script with lsgui /etc and at that point it will display that dir but when I try to navigate to another dir it faults again.

#!/bin/bash

output=${1-$PWD}
IFS=$'\r\n' lss=($(ls -1 $output))
for ((i=0;i<${#lss[@]};i++));do
x+=($i \"${lss[$i]}\")
done

justdir=($(basename $output))
desc=($(grep $justdir /root/lsgui.conf))
if [ -z $desc ]
then
desc=$output
fi

dialog --keep-tite --title 'lsgui' --menu $desc 40 70 ${#lss[@]} ${x[@]} 2>/tmp/lsgui.$$

if [ $? -gt 0 ]; then
rm -f /tmp/lsgui.$$
clear
exit 0
fi

result=`cat /tmp/lsgui.$$`

case $? in
0)
  if [ -d ${lss[$result]} ];then
    /root/lsgui $output/${lss[$result]}
  else
    dialog --keep-tite --title "${lss[$result]}" --textbox $output/${lss[$result]} 40 70
  fi

esac

UPDATE

The problem was if [ -d ${lss[$result]} ];then. It was looking to open a file in a dir. This was fixed by changing the previous statement to if [ -d $output/${lss[$result]} ];then. I probably could have prevented the segfault in the first place by checking if the dialog textbox was a file or not.

closed as off-topic by Thomas Dickey, Jeff Schaller, Scott, Anthon, Jakuje Apr 17 '16 at 8:27

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Thomas Dickey, Jeff Schaller, Scott, Anthon, Jakuje
If this question can be reworded to fit the rules in the help center, please edit the question.