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

  • SEARCH
  • Home
  • 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 6878683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:45:14+00:00 2026-05-27T04:45:14+00:00

I basically want to write me a bash script, where I’d generate a couple

  • 0

I basically want to write me a bash script, where I’d generate a couple of big files using heredoc; and then run some commands using those files.

It is understood that (obviously) the heredoc files need to be generated before the commands run – however, what irritates me in that arrangement, is that I must also write the ‘heredoc’ statements code, before I write the command code.

So I thought I’d write the heredoc statements in a function – but still the same problem here: Chapter 24. Functions says:

The function definition must precede the first call to it. There is no method of “declaring” the function, as, for example, in C.

Indeed, it is so:

$ cat > test.sh <<EOF
testo

function testo {
  echo "a"
}
EOF

$ bash test.sh 
test.sh: line 1: testo: command not found

Then I thought maybe I could place some labels and jump around with GOTO, as in (pseudocode):

$ cat > test.sh <<EOF
goto :FUNCLABEL

:MAIN
testo

goto :EXIT

:FUNCLABEL
function testo {
  echo "a"
}
goto MAIN

:EXIT

… but it turns out BASH goto doesn’t exist either.

My only goal is that – I want to first write the “core” of the script file, which is some five-six commands; and only then write the heredoc statements in the script file (which may have hundreds of lines); having the heredocs first really makes reading the code difficult for me. Is there any way to achieve that?

  • 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-27T04:45:15+00:00Added an answer on May 27, 2026 at 4:45 am

    A common technique is:

    #!/bin/sh
    
    main() {
      cmd_list
    }
    
    cat > file1 << EOF
    big HEREDOC
    EOF
    
    main "$@"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write some VBA script so that when I start my access
I'm trying to write a bash script and I needed to do some floating
I want to write some programs using Java comm api. I am not able
I want to write a python script (Yes not Bash) that will use flac
I want to write some C code such that gcc using the -msse4.1 flag
Okay I basically want to get the ball rolling and write some CPPUnit tests
I want to write a simple SMPP Server that basically forwards traffic to another
I want to write a rule in prolog, which basically says If a user
I'm trying to write my first iterator class / container type. Basically, I want
I have a input that you enter a URL, i basically want to write

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.