0

I have this code and when I try it in FreeBSD it shows me a lot of errors... how can I fix it? I check directories, if it match with variable IGN. NAME_d should be an array.

max_d=$(find "${DIR}" -type d | wc -l)

for i in `seq 1 $max_d`
do
  check_d=$(find "${DIR}" -type d | head -n "${i}" | tail -n -1 | tr '\/' '\n' | egrep -n "${IGN}")

  if [ ! -z "$check_d" ]; then

    NAME_d+=$i"d "

  fi

done

directory_d=${NAME_d[*]}
sedCmds_d=${directory_d// /;}

erroe

3
  • this is the second time today I see this seq loop with a previous find and another find in the loop reading only one line from each find. This is far from optimal. Rethink your work! How about let x=0; find . -type d | while read dir; do let 'x++'; DO YOUR WORK WITH $dir HERE, POSSIBLY ALSO USING LINENO $x.; done Commented Mar 28, 2016 at 18:17
  • 1
    You don't appear to be using bash, which has allowed += for assignment statements since version 3.1. In addition, NAME_d is not an array even if you were using bash. Commented Mar 28, 2016 at 18:17
  • Provide information as image iff they can't be posted as text (readable, searchable, etc). Commented Mar 28, 2016 at 18:24

2 Answers 2

1

Arrays are a bashism not supported by the Almquist shell, the default bourne style shell on FreeBSD (i.e. /bin/sh). An advantage of the shell is that most scripts run about 3 times faster.

If you want to use bashisms, use bash to execute your script. E.g. call it bash dirstat.sh or change the shebang.

This is the correct one for FreeBSD.

#!/usr/local/bin/bash

This is the portable version but requires PATH to be set:

#!/usr/bin/env bash

You also might have to install bash first: pkg add bash

Sign up to request clarification or add additional context in comments.

Comments

1

Not sure if it will solve it, but if you're using bash, you should initiate NAME_d as an array

NAME_d=()

and then adding to the array you should also use parens, e.g.

NAME_d+=("${i}d ")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.