schnell2632
June 3rd, 2011, 05:29 PM
Hi,
I am new to shell scripting and i am facing this problem. I have a following shell script file
#!/bin/sh
# Step 1 : Get the contents of the folder and fill the array
declare my_array=(`ls -l`)
# get number of elements in the array
ELEMENTS=${#my_array[@]}
# echo each element in array ; for loop
for (( i=0;i<$ELEMENTS;i++)); do
echo ${my_array[${i}]}
done
# END
When I execute the command directly in the terminal one by one, everything works fine and I get an array filled with the contents of the ls command. But when i create a script file TestScript.sh and execute it in the shell I get the following error:
TestScript.sh: 3: Syntax error: "(" unexpected
I can not figure out why am I getting this error.
Thanks in advance,
Kind Regards
I am new to shell scripting and i am facing this problem. I have a following shell script file
#!/bin/sh
# Step 1 : Get the contents of the folder and fill the array
declare my_array=(`ls -l`)
# get number of elements in the array
ELEMENTS=${#my_array[@]}
# echo each element in array ; for loop
for (( i=0;i<$ELEMENTS;i++)); do
echo ${my_array[${i}]}
done
# END
When I execute the command directly in the terminal one by one, everything works fine and I get an array filled with the contents of the ls command. But when i create a script file TestScript.sh and execute it in the shell I get the following error:
TestScript.sh: 3: Syntax error: "(" unexpected
I can not figure out why am I getting this error.
Thanks in advance,
Kind Regards