Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax Error in BASH Shell

Status
Not open for further replies.

wak1967

Technical User
Feb 22, 2003
8
GB
Hi again

When I run this command shell (test.sh):

#!/bin/sh
BACKUPLOG="my_backup-$(date '+%Y.%m.%d:%H:%M').log"
export BACKUPLOG
#
cat > $BACKUPLOG 2> <<-EOF
Backup started at: `date`
EOF
#

I get the following error.

bash test.sh : line 6: syntax error near unexpected token `<<-'
bash test.sh : `cat > BACKUPLOG 2> <<- EOF'
Can anyone tell me why the file is not being created and wht the error is occuring?

Thanks
 
#!/bin/sh
# this is Bourne shell - Bourne's active functions can ONLY
# be denoted with the BACK QUOTES
BACKUPLOG=&quot;my_backup-`date '+%Y.%m.%d:%H:%M'`.log&quot;
# no need to export
#export BACKUPLOG
#
cat > ${BACKUPLOG} <<EOF
Backup started at: `date`
EOF
#
vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
I've tried this but I'm still getting the same error. Any ideas?
 
Hi,

When using a here document, make sure the closing marker
is at the begining of the line and that nothing else is on the line. It your post it is like this:

cat > $BACKUPLOG 2> <<-EOF
Backup started at: `date`
EOF <-- this is the problem

Try it like this:
cat <<EOF > $BACKUPLOG
Backup started at: `date`
EOF

-jim
 
The line

cat > $BACKUPLOG 2> <<-EOF

redirects stderr but doesn't tell it where to go. Add a filename after 2>.

Using the a here document with the <<- form allows closure symbols that aren't left justified (but only if using tabs for indentation, not spaces). That's not the problem cited, but it might cause incorrect output if you use spaces for indentation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top