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 957843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:46:20+00:00 2026-05-16T00:46:20+00:00

I have a bash-script (let’s call it /usr/bin/bosh ) using the following she-bang line:

  • 0

I have a bash-script (let’s call it /usr/bin/bosh) using the following she-bang line:

#!/bin/bash --init-file

It defines a couple of functions, and generally puts the interactive shell in an environment where the user can control a bunch of stuff that I want. This works pretty well. Now for the interesting part, I’d like to be able to let users use this in-between-layer for writing new scripts, without explicitly havnig to source this one. Is that at all possible?

I tried writing a script (let’s call it /usr/bin/foo) using the she-bang line

#!/usr/bin/bosh

Which I thought, would be rewritten to execute the command

/usr/bin/bosh /usr/bin/foo

which in turn would result in

/bin/bash --init-file /usr/bin/bosh /usr/bin/foo

But it doesn’t work, /usr/bin/foo gets executed, but /usr/bin/bosh is not source before that.

How can I make it source the init file even though the script is not interactive? Or would I have to write a wrapper script for that? I thought of having a script like this

#!/bin/bash
. /usr/bin/bosh
. "$1"

But that wouldn’t turn into an interactive shell if I don’t specify a script to run, which would be kind of a shame.

EDIT
For clarification, what I’m really asking is, how can I make bash source a file (like –init-file) regardless whether it’s interactive (before starting the interactive part) or not (before executing the script)? If there’s no way, is there any other way to solve my problem perhaps?

  • 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-16T00:46:21+00:00Added an answer on May 16, 2026 at 12:46 am

    The program specified by the #! cannot be another script I’m afraid at least until linux kernel 2.6.27.9, which allows this feature. If you run strace on foo you’ll see that you’d get an ENOEXEC or exec format error, because bosh cannot be executed as a standalone program.

    What is happening is that instead of /bin/bosh being executed and handed foo as input, your login shell is simply silently falling back to executing foo itself in a sub-shell, which is why it seems to almost work.

    A wrapper or C program that launches bash the way you want are probably your only options. Even with an upgrade to your kernel, it will not quite work the way you want I’m afraid.

    Everything you ever wanted to know about #! here: http://www.in-ulm.de/~mascheck/various/shebang/

    EDIT: If your kernel really does support chained scripts, then a work-around for /usr/bin/bosh might be something like:

    #!/bin/bash
    if [ ! $PS1 ]; then
       exec /bin/bash --init-file "$0" -i "$@"
    fi
    ... rest of bosh init file ...
    

    An exec seems to be unavoidable to get this to work the way you want it to.

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

Sidebar

Related Questions

Let's say I have a Bash script called foo.sh . I'd like to call
Let's imagine I have a bash script, where I call this: bash -c some_command
I have a bash script which is getting options (using getopts). Let say they
Have such script: #! /bin/bash typeset -i i END let END=500 i=1 remainder=1 accum=use
Let’s say I have the following Bash script: while read SCRIPT_SOURCE_LINE; do echo $SCRIPT_SOURCE_LINE
I have a bash script, that I run like this via the command line:
I have a bash script mystuff containing a line like lynx -dump http://example.com >tmpfile
I have a bash script that runs (something like) the following command: vim -E
#!/bin/bash #trash.sh $TRASHDIR=$HOME/trash #Does not exist yet, i have loops further in #the script
Say I have a file at the URL http://mywebsite.example/myscript.txt that contains a script: #!/bin/bash

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.