?
Solved

Syntax error at line 4 : `<<' is not matched

Posted on 2003-03-24
5
Medium Priority
?
1,365 Views
Last Modified: 2013-12-27
Dear experts,

I am trying to write a shell script to include a line in file.
There are many files that I need to include the line "connect internal".
I have pasted below a sample of the script:
*****************************
for j in `ls *.txt`
do
 ed -s /tmp/unix.txt<<EOF
 H
 f
 $ i
 connect internal
 .
 w
 EOF
done

*****************************
Whenever I execute the above script I get the message:

stv10750:/tmp# > ./modifyscript.sh
./modifyscript.sh[2]: Syntax error at line 4 : `<<' is not matched.

Could you please help me in this.

Many thanks
Mike
0
Comment
Question by:miker123
5 Comments
 
LVL 1

Expert Comment

by:SumeshDaftary
ID: 8196905
Your 4th line says

H only

What it means (as per your idea)

0
 
LVL 5

Expert Comment

by:ecw
ID: 8198902
Make sure there are no spaces before or after EOF.
0
 
LVL 2

Accepted Solution

by:
soupdragon earned 225 total points
ID: 8199401
I don't see the variable $j used in your code snippet and I'm not sure you can pass a variable into ed. If you just want to add text at the end of each file use echo.

for j in `ls *.txt`
do
echo "connect internal" >>$j
done

0
 
LVL 5

Expert Comment

by:ecw
ID: 8199840
The variable is not being passed into ed.  The variable is expanded by the shell before the contents of the here document are passed to ed.  If <<EOF was <<"EOF" or <<'EOF' the variable would not be evaluated.
0
 
LVL 4

Expert Comment

by:Otetelisanu
ID: 8200654
For and after EOF must by no
spaces
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question