Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I would be very curious to see what the first line of the file you were trying to run looked like
For instance, #!/bin/sh would call up the shell that /bin/sh points to (usually bash). However, a non-exsistant shell will give you an error similar to the one the you got (try changing #!/bin/sh to #!/bin/trash to see what I'm talking about).
You can also override these pesky shells by envoking your script like this:
I had this same problem and am embarassed to admit that I just figured out what the problem was. I post it here in the event that someone else searches for the problem like I did.
I was getting "bad interpreter" errors when I tried to execute some scripts via ./scriptname and such. I JUST realized that it only seemed to happen on a certain filesystem. You guessed it ... it was a FAT32 filesystem I had mounted under Linux for file transfer purposes.
I've also got the bad interpreter error; it was caused because the script had the DOS CR LF character line ending. I had been editing the script in Windows (I know, evil--but at least I was in the cygwin environment).
I used the "od -c" command to diagnose the problem.
I used the "fromdos" command to straighen the problem out.
The cryptic "Bad Interpreter" error message can be generated if a nested shell script does not have execute permission.
For example, you have
two shell scripts, a.sh and b.sh.
a.sh does some stuff then runs b.sh
if b.sh is not executable (chmod a+x) you may get a "Bad Interpreter". One might expect a more enlightening error message such as "no execute permission for subshell". rather than a permission related error.
One way to determine if this is your problem is to use a debugging option for your shell.
For example you can try
"/bin/bash -x a.sh"
This will run a.sh, and display every executed line.
Originally posted by lyle_s I've also got the bad interpreter error; it was caused because the script had the DOS CR LF character line ending. I had been editing the script in Windows (I know, evil--but at least I was in the cygwin environment).
I used the "od -c" command to diagnose the problem.
I used the "fromdos" command to straighen the problem out.
Lyle
This saved my day! I had the same problem, now everything is working as expected again. Many thanks!!!
The same script in the same folder on the same partition executing the same commands, works once and then after a reboot for another purpose no workies
Code:
[david@xpbeast packers]$ ./script2
bash: ./script2: /bin/bash: bad interpreter: Permission denied
I got it running using
Code:
bash ./script2
without a problem.
1) it was in unix file format
2) the partition entry in fstab hadnt changed
3) the shebang was #!/bin/bash
4) it was an executiable file (hence calling bash specifically worked)
5) i tried as root, same response
I got it working, so thats the main thing, but i find it very curious though
That's odd. Please post the output of the "mount" command run without arguments, the contents of your /etc/fstab, and which partition your script2 resides on.
I know you said you didn't change anything in /etc/fstab before the reboot, but maybe the reboot isn't the point at which it stopped working, only the point at which you noticed it stopped working.
I later found (just recently actually) it was a NFS mount. Same name dir with the same named files oops
I thought i had executed scripts before on my NFS mounts, like i installed the system on an NFS mount that has the same arguments as this NFS mount in question.
Oh well, the work around worked fine anyways
Thanx again for the reply, i guess i should more before posting
Hi! I had the same problem, and the cause was the mounting options for /home.
To enhance security if some user tried to compile and run programs, I added 'noexec,nosuid' to the options for /home in /etc/fstab.
bash, as the which command told me, is /usr/bin/bash, linked in Slackware to /bin/bash which is not on the /home partition, so the command
bash /home/fjor/script
run successfully, but if I do a chmod +x script, I never could run it as ./script or /home/fjor/script, because /home does not allow execute access to files.
I was trapped by my own paranoia but, in a second thinking, that were the behaviour I wanted.
So, if I want now to create user accesible scripts to do maintenance or simplify things like list the names of the users in my server, or find the email of someone, I move the scripts to /usr/local/bin for normal users, or to /usr/local/sbin, for only root access.
Hi all,
I had exactly the same problem - thanks to all of your postings - I went and added the "exec" directive in my
/etc/fstab file for the specific nfs mount that I was using. On remounting, my scripts ran without any problem.
In my case I've the same problem and the solutions given have not worked. I have a simple script:
#! /bin/bash
#
# cpu_hog
#
# Small shell script for displaying top 10 processes.
#
ps -efF | sort -r | head
<-----------end script--------------->
Imported from an AIX Unix where it runs under the #!/bin/ksh korn
I put the script in /usr/bin set 755 and am running as root. Path to /bin/bash is set right in my env and bash scripts from source work but this one doesn't.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.