Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 199231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:00:20+00:00 2026-05-11T17:00:20+00:00

I have the following code in a shell script. This only seems to work

  • 0

I have the following code in a shell script.
This only seems to work when it is not defined in a function.
The problematic line is the one containing the “<<“.
The error message is

“./run: line 210: syntax error:
unexpected end of file”

How can I write this correctly within a function?

init_database()
{
    cd ../cfg
    db.sh << ENDC
    $DB_ADMIN

    0
    y
    n
    ENDC

    check_status

    sqlplus $DB_SCHEMA@$DB_NAME < initial_data.sql

    cd -
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:00:21+00:00Added an answer on May 11, 2026 at 5:00 pm

    There are a number of ways to fix that problem.

    1/ Unindent the here document end marker, such as:

    cat <<EOF
        hello
        $PWD
    EOF
    

    but that will make your code look ugly.

    2/ “Indent” the here document begin marker:

    cat <<' EOF'
        hello
        $PWD
        EOF
    

    where that bit before the first EOF is exactly the same as the before the second (tab, four spaces, two tabs, whatever). This allows you to keep your nice indenting, although it doesn’t expand variables inside the here-document ($PWD doesn’t change).

    3/ Allow tabs to be stripped from the start of input lines and the end marker.

    cat <<-EOF
        hello
        $PWD
        EOF
    

    but there’s no way to get tabs into the beginnings of lines.

    4/ For your purposes, you can also use:

    (   echo "$DB_ADMIN";
        echo "" ;
        echo "0" ;
        echo "y" ;
        echo "n"
    ) | db.sh
    check_status
    sqlplus $DB_SCHEMA@$DB_NAME < initial_data.sql
    cd -
    

    I believe number 4 is the best option for you. It allows nice lining up of the input, tabs and spaces anywhere in the lines and variable expansion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 191k
  • Answers 191k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer SELECT * FROM POWDER WHERE IsNumeric(Name) = 1 IsNumeric returns… May 12, 2026 at 6:12 pm
  • Editorial Team
    Editorial Team added an answer You can retrieve separate date and time parts like: SELECT… May 12, 2026 at 6:12 pm
  • Editorial Team
    Editorial Team added an answer I have no experience of writing real-world gps applications for… May 12, 2026 at 6:12 pm

Related Questions

I am attempting to write a one-line Perl script that will toggle a line
Suppose I have a text file with data separated by whitespace into columns. I
I am looking at trying to create a python server, which allows me to
Is there any way to build some time counter that enable parts of a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.