0

In a bash script I split a line into pieces and then again split one of the pieces by "/".

example of my input is:

line="./function -o=25-32 -f=1000 -t=1000 -r=SNISSWWN /../allfiles/1BE3C_25.pdb >Log.txt"

The code I use is as below:

stringarray=($line)
pdb=${stringarray[5]}
echo "The 5th element is: "$pdb

arr=$(echo $pdb | tr "/" "\n")

echo "elements in arr are: "
for x in $arr
do
    echo $x
done

echo "The second element in arr is:"
echo  ${arr[2]}

The out put I get is:

The 5th element is: /../allfiles/1BE3C_25.pdb elements in arr are: .. allfiles 1BE3C_25.pdb

The second element in arr is:

which means that I can't access the elements in arr.

Can you please tell me how I can access that?

thank you

1 Answer 1

1

You are assigning arr as a string, not an array. You're missing a set of parentheses

arr=( $(echo $pdb | tr "/" "\n") )
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.