I am trying to find the index of an list entry using this simple method:
#!/bin/sh
partList="500 1000 2000 4000"
a=( $partList )
echo ${a["500"]}
this returns Syntax error: "(" unexpected
. And the same error if I try echo ${a[500]}
. Where I was hoping it would return 0
if using 500
.
I am simply looking for a quick and dirty way to tell, when am looping over a list as so:
for j in $partList; do
if [ $j is the first entry in the list $partList ]; then
stuff happens..
done
done
whether or not I have used the first element of that list and if so then do some logic.
I thought I could do this easily using the index of the list. But this appears difficult with #!/bin/sh
.
Any suggestions?