Cannot use "./" to execute a shell script

9,808

Solution 1

The errors you see may be caused by trying to run an executable on a media mounted with the "noexe" property. Type mount, and examine the properties of the device which contains the script. Change the /etc/fstab properties of the mount if necessary.

Solution 2

The only thing that would cause this is if the script is not executable. I know you said the executable bit is set, but make sure:

chmod +x scriptname.sh

Solution 3

I've read of various problems arising with auto-completion, not necessarily with 12.04, and the following two options seem worth trying:

First, try disabling bash programmable completion: Comment-out these three lines in both /etc/bash.bashrc and in the user's $HOME/.bashrc:

 if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
     . /etc/bash_completion
 fi

You may find that those lines are already commented-out with # in front, in which case just leave it as-is.

So secondly, try re-installing bash-completion:

sudo apt-get purge bash-completion
sudo mv /etc/bash_completion.d /etc/bash_completion.d.bak
sudo apt-get install bash-completion
Share:
9,808

Related videos on Youtube

adeliefan
Author by

adeliefan

Updated on September 18, 2022

Comments

  • adeliefan
    adeliefan over 1 year

    Maybe someone here would be able to help me out. Have installed Ubuntu 12.04 LTS (kubuntu) on two machines. The .bashrc and .bash_profile files are identical as the file structures on each machine is the same.

    On machine 1 I run bash scripts within a terminal window with the simple: ./scriptname.sh

    On machine 2, I cannot do this and must use: sh scriptname.sh Nor can I use ./ and tab-complete the script filename.

    All executable bits are set correctly, all files and folders have the correct permissions. In the header of the scripts the shebang is set correctly.

    Any ideas why this would be occurring?

    Cheers

    • fiatux
      fiatux over 11 years
      also asked on unix&linux and stackoverflow
    • Lars Rohrbach
      Lars Rohrbach over 11 years
      Is this for root, or a non-root user? Does echo $SHELL on both machines confirm that the shell is bash?
    • adeliefan
      adeliefan over 11 years
      non-root user, echo $SHELL returns /bin/bash on both machines
  • adeliefan
    adeliefan over 11 years
    Nope - its definitely set right. I figure there has to be something wrong with my environmental set up (.bashrc or .bash_profile) but cant see where it has snuck in.
  • adeliefan
    adeliefan over 11 years
    Thanks for the suggestion Lars, it made no difference though.
  • Lars Rohrbach
    Lars Rohrbach over 11 years
    Well, darn. I presume you re-logged-in after doing this?
  • swist
    swist over 5 years
    Thanks. I have need to changed properties to ext4 rw,relatime