Hello there,
I am a newbie to unix and i have been trying to code a shell script for bash shell which reads the files in a folder using ls and writes them into an array variable. But, i am running into several errors while running the script. The script is given below:
#!/bin/bash
script_loc=/export/home/oracle/HY_DUMP
cd $script_loc
num=0
for i in `ls -1 | grep -v ^'[.]\|[..]'$ | sed s/' '/'\\ '/g` ;
do
testarray[$num]=$i
echo ${testarray[$num]}
num = 'expr $num + 1'
done
It gives me the following error when i run the above code:
Usage: grep -hblcnsviw pattern file ...
script_1.sh: [.]\|[..]$: Not Found
When i run the command : ls -1 | grep -v ^'[.]\|[..]'$ | sed s/' '/'\\ '/g individually on the command line, i get a list of all the files neatly.
Any help is highly appreciated!