I want to populate an array with the lines of a text file, where each line of the file is a position in the array, separated by a space (for example array[0] = "int", array[1]="main(){}", array[2]="int"...). But in doing so, some characters are considered as shell commands. Below the code to be read and my script:
Shell Script:
#!/bin/bash
array=($(cat $1))
for i in "${array[@]}"; do
  echo "$i"
done
Source code to be read:
int main(){
    int i;
    /** /** **/ (this part is treated as a shell command)
    i = 3 + 2;
    return 0;
}
Output:
 p0ng   ~ > ~/Compiladores  sh teste.sh codigoFonte.c 
int
main(){
int
i;
/bin
/boot
/dev
/etc
/home
/lib
/lib64
/lost+found
/mnt
/openwrt
/opt
/proc
/root
/run
/sbin
/srv
/sys
/tmp
/usr
/var
/bin
/boot
/dev
/etc
/home
/lib
/lib64
/lost+found
/mnt
/openwrt
/opt
/proc
/root
/run
/sbin
/srv
/sys
/tmp
/usr
/var
Projeto/
i
=
3
+
2;
return
0;
}
Thanks for the help!
-- UPDATE --
I had to make two changes to the script (thanks glenn jackman):
#!/bin/bash
mapfile -t array < "$1" # <--- HERE
for i in "${array[*]}"; do
  echo "$i"     # ^--- and HERE (i don't know why)
done
Now it works! :)
