Results 1 to 5 of 5

Thread: !#bin/bash and !#/usr/bin/env bash

  1. #1
    Join Date
    Dec 2007
    Beans
    8,451
    Distro
    Lubuntu 16.04 Xenial Xerus

    !#bin/bash and !#/usr/bin/env bash

    What is the difference? Are there times one is preferable?

    In the following codes, both work the same:
    Code:
    #!/bin/bash
    
    sleep 1m;
    
     COUNTER=0
        while [  $COUNTER -lt 10 ]; do
           mplayer -really-quiet /usr/share/sounds/freedesktop/stereo/phone-incoming-call.oga
              let COUNTER=COUNTER+1 
        done
    and
    Code:
    #!/usr/bin/env bash
    
    sleep 1m;
    
     COUNTER=0
        while [  $COUNTER -lt 10 ]; do
           mplayer -really-quiet /usr/share/sounds/freedesktop/stereo/phone-incoming-call.oga
              let COUNTER=COUNTER+1 
        done
    Shortened urls: See point #11 here. And clicking on them could be risky.
    Use ubuntu-support-status with caution.

  2. #2
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: !#bin/bash and !#/usr/bin/env bash

    /bin/bash points directly to the binary file
    env abstracts the true location away which is useful in case of less essential stuff that can be put in different locations in different distros. Obviously this improves portability, you don't care where distro managers put let's say python - it's the env's job to find it. Also in case of multiple versions in parallel you can switch the default one and have the scripts follow.

    http://stackoverflow.com/questions/2...-python-script
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  3. #3
    Join Date
    Dec 2007
    Beans
    8,451
    Distro
    Lubuntu 16.04 Xenial Xerus

    Re: !#bin/bash and !#/usr/bin/env bash

    Thank you

    Marking it [Solved]
    Shortened urls: See point #11 here. And clicking on them could be risky.
    Use ubuntu-support-status with caution.

  4. #4

    Re: !#bin/bash and !#/usr/bin/env bash

    Quote Originally Posted by Vaphell View Post
    env abstracts the true location away which is useful in case of less essential stuff that can be put in different locations in different distros.
    Interesting!

    Is env always located in /usr/bin/env for all distros?

    Does it exists in older *nixes? (Solaris, Freebsd, etc)
    How strange it is, that a fool or a knave, with riches, should be treated with more respect by the world, than a good man, or a wise man in poverty!

  5. #5
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: !#bin/bash and !#/usr/bin/env bash

    Quote Originally Posted by azzamite View Post
    Interesting!

    Is env always located in /usr/bin/env for all distros?

    Does it exists in older *nixes? (Solaris, Freebsd, etc)
    This should answer all your questions: http://www.in-ulm.de/~mascheck/various/shebang/


    Here is another interesting article which is also related to this topic:
    http://www.freedesktop.org/wiki/Soft...orTheUsrMerge/

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •