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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:00:28+00:00 2026-05-30T19:00:28+00:00

What is reason behind writing #! /bin/bash at the very starting of every bash

  • 0

What is reason behind writing

#! /bin/bash

at the very starting of every bash script ?

I means, I know that it is kind of hack but I want to know how it exactly works ?

  • 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-30T19:00:30+00:00Added an answer on May 30, 2026 at 7:00 pm

    If you call the script with an explicit interpreter, like

     bash foo.sh
     /bin/bash foo.sh
     dash foo.sh
     sh foo.sh
    

    your choosen interpreter is used, no matter what the shebang says, which is just a comment.

    If you make the script executable, and start it:

     chmod a+x foo.sh
     ./foo.sh
    

    the kernel looks for the shebang and starts the program with the therein specified interpreter. Since the kernel doesn’t know the PATH, the whole path has to be given, or env has to be used:

     #!/usr/bin/env python 
    

    to choose the local path for a program.

    Since dash, bash, zsh and so on aren’t fully compatible, you should call the program without a specific interpreter, because the author should have known what he does.

    Maybe on your system sh is a link to /bin/bash, but beware! The shell can introspect how it was called, and bash can act in a way, called POSIX mode, which is slightly different and only a subset of what it normally does.

    If you write scripts for installation or for servers, which might run on different platforms – think OsX, Linux, Solaris and so on, where different shells are available, you will try to restrict yourself to this subset, to gain a compatible, reusable result.

    But on your private machine, you might prefer the more convenient shells like zsh and bash.

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

Sidebar

Related Questions

i know it's not possible, i'm trying to understand the true reason behind it
I can usually understand the reason behind a compiler warning, but this one seems
Curious to know the reason behind not allowing updating UI elements from background thread
Is there any reason behind using date(January 1st, 1970) as default standard for time
The Question actually says it all. The reason behind this question is I am
REASON: I'm working on an emergency alert application that needs to display information on
The reason I am asking is that I am thinking of building a foot
The reason? Pure nostalgia. Anyway, there was a standard for Basic that was published
The reason I'm asking this is because there is a validation in OpenERP that
This is a situation I'm generally facing while writing SQL queries. I think that

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.