0

This line from a loop is supposed to add the three strings together

for each $drivecount
${drives[$drivecount]}=${info[$count+1]}" "${info[$count+2]}" "${info[$count+3]}

Here is the error I am getting:

./erasehd.sh: line 17: =/dev/sda: 80.0 GB: No such file or directory

It looks like it is including the = as part of the first string?

1 Answer 1

2
./erasehd.sh: line 17: =/dev/sda: 80.0 GB: No such file or directory

No, its ignoring the undeclared variable at the front and trying to execute =/dev/sda... as a command. ;-) .... You want

for each $drivecount
drives[$drivecount]=${info[$count+1]}" "${info[$count+2]}" "${info[$count+3]}

When setting a variable, you never want a leading '$' on a variable, or put another way, typically you don't want a '$' on the left-hand-side of the '=' assignment.

I'm not familiar with the for each construct in bash. Are you sure that is right? I would expect something like

for drivecount in 1 2 3 ; do
 ....

Finally, the syntax you included is used for referencing an array element, unrelated to assignments.

for dc in 1 2 3 ; do
  echo ${drives[$dc]}
done

IHTH.

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

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.