bash error that isn't? - Debian

This is a discussion on bash error that isn't? - Debian ; whereis shows that bash is at /bin/bash me@myPlace:~$ whereis bash bash: /bin/bash /etc/bash.bashrc /usr/share/man/man1/bash.1.gz But when I run a script I get: me@myPlace:~$ ./theScript ./theScript: line 1: !#/bin/bash: No such file or directory --does everything correctly-- me@myPlace:~$ It all works, ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: bash error that isn't?

  1. bash error that isn't?

    whereis shows that bash is at /bin/bash

    me@myPlace:~$ whereis bash
    bash: /bin/bash /etc/bash.bashrc /usr/share/man/man1/bash.1.gz


    But when I run a script I get:

    me@myPlace:~$ ./theScript
    ./theScript: line 1: !#/bin/bash: No such file or directory
    --does everything correctly--
    me@myPlace:~$

    It all works, but why the "No such file or directory" message?

    Dave

  2. Re: bash error that isn't?

    Dave Murray wrote:
    > whereis shows that bash is at /bin/bash
    >
    > me@myPlace:~$ whereis bash
    > bash: /bin/bash /etc/bash.bashrc /usr/share/man/man1/bash.1.gz
    >
    >
    > But when I run a script I get:
    >
    > me@myPlace:~$ ./theScript
    > ./theScript: line 1: !#/bin/bash: No such file or directory
    > --does everything correctly--
    > me@myPlace:~$
    >
    > It all works, but why the "No such file or directory" message?


    Because, you got the line wrong :-)

    The line /should/ read
    #!/bin/bash

    That's
    hash (#)
    bang (!)
    /bin/bash

    The hash (#) introduces a comment, making the rest of the line 'null' as far
    as bash is concerned

    OTOH, what you wrote
    bang (!)
    hash (#)
    /bin/bash

    started with a bang (!), which is a unary not operator for an expression. The
    unary not /must/ be followed by an expression, which (in it's simplest form)
    is the name of an executable.

    ! someprogram
    would run
    someprogram
    and evaluate to a value of 0 if someprogram returned a non-zero value.

    With your starting line, the shell tried to run the executable called
    "#/bin/bash" (in order to logically NOT its resultcode) and could not find
    that program. So, it reported back to you that there was no such file or
    directory as "#/bin/bash"






    --
    Lew Pitcher

    Master Codewright & JOAT-in-training | Registered Linux User #112576
    http://pitcher.digitalfreehold.ca/ | GPG public key available by request
    ---------- Slackware - Because I know what I'm doing. ------


  3. Re: bash error that isn't?

    Lew Pitcher wrote:
    > Dave Murray wrote:
    >> whereis shows that bash is at /bin/bash
    >>
    >> me@myPlace:~$ whereis bash
    >> bash: /bin/bash /etc/bash.bashrc /usr/share/man/man1/bash.1.gz
    >>
    >>
    >> But when I run a script I get:
    >>
    >> me@myPlace:~$ ./theScript
    >> ./theScript: line 1: !#/bin/bash: No such file or directory
    >> --does everything correctly--
    >> me@myPlace:~$
    >>
    >> It all works, but why the "No such file or directory" message?

    >
    > Because, you got the line wrong :-)
    >
    > The line /should/ read
    > #!/bin/bash
    >
    > That's
    > hash (#)
    > bang (!)
    > /bin/bash
    >
    > The hash (#) introduces a comment, making the rest of the line 'null' as far
    > as bash is concerned
    >
    > OTOH, what you wrote
    > bang (!)
    > hash (#)
    > /bin/bash
    >
    > started with a bang (!), which is a unary not operator for an expression. The
    > unary not /must/ be followed by an expression, which (in it's simplest form)
    > is the name of an executable.
    >
    > ! someprogram
    > would run
    > someprogram
    > and evaluate to a value of 0 if someprogram returned a non-zero value.
    >
    > With your starting line, the shell tried to run the executable called
    > "#/bin/bash" (in order to logically NOT its resultcode) and could not find
    > that program. So, it reported back to you that there was no such file or
    > directory as "#/bin/bash"



    Duh! Dyslexia strikes again. Thanks,

    Dave

+ Reply to Thread