Shell execution on FAT32?

Is it possible to somehow execute shell scripts on FAT32 file system? Like, I need to run this script on the FAT32 drive, and it gives me a bad interpreter: permission denied error. Moving all the files to an Ext3 would be hard as I have one huge FAT32 for all programs, documents etc., although possible.

The problem is generally not the FAT filesystem per se, but that usually files edited with a DOS/Windows editor have CR-NL line endings instead of the usual NL only Unix/Linux line ending. This gives rise to the bad interpreter error as what you are attempting to execute is literally /bin/sh^M (where ^M stands for a control-M). Fix this at the editor level (vim allows you to set the file format) or convert the files.

Even if you try to get around this by doing:

sh script.sh

the ^M on the other lines will mess up things.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

There is also a dos2unix command you can run against a file that will
convert the line endings nicely for you.

Good luck.

ken yap wrote:
> The problem is generally not the FAT filesystem per se, but that usually
> files edited with a DOS/Windows editor have CR-NL line endings instead
> of the usual NL only Unix/Linux line ending. This gives rise to the bad
> interpreter error as what you are attempting to execute is literally
> /bin/sh^M (where ^M stands for a control-M). Fix this at the editor
> level (vim allows you to set the file format) or convert the files.
>
> Even if you try to get around this by doing:
>
>
> Code:
> --------------------
> sh script.sh
> --------------------
>
>
> the ^M on the other lines will mess up things.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIxAi73s42bA80+9kRAnUJAJ48X+MtUzQz+Jd4/UnV6Sq05lJdFQCfacXu
z3SqfEYyNY8aJIM1zxCa+iE=
=dLXm
-----END PGP SIGNATURE-----

I made the script by a copy-paste to KWrite. That messes it too? And do I need anything else than Bash for the dos2unix command, and what’s the syntax? “# dos2unix filename”?

On 2008-09-07, GreatEmerald <GreatEmerald@no-mx.forums.opensuse.org> wrote:

> Is it possible to somehow execute shell scripts on FAT32 file system?
> Like, I need to run ‘this script’ (http://pastebin.com/m6441c3a2) on the
> FAT32 drive, and it gives me a bad interpreter: permission denied error.
> Moving all the files to an Ext3 would be hard as I have one huge FAT32
> for all programs, documents etc., although possible.

Assuming the problem is not the EOL character, as you don’t mension it…

The only “problem” with running scripts from a FAT partition is that you
can’t set them “executable”. But for that, the solution is allready given.
Just specify the name of the shell before the scripts name:
bash ‘this script’ or
sh ‘this script’ for instance.

If you want to avoid having to type that, you can also configure mc
(Midnight Commander) to launch the script with the shell, based on the file
extension.

I did this to run python scripts from a Windows drive. When I’d hit <enter>
on a *.py file, mc would run python with that file.
(works from whatever kind of partition, as long as you can read the file)


Hanlon’s Razor:
Never attribute to malice that which is
adequately explained by stupidity.

On 2008-09-07, GreatEmerald <GreatEmerald@no-mx.forums.opensuse.org> wrote:

> I made the script by a copy-paste to KWrite. That messes it too? And do
> I need anything else than Bash for the dos2unix command, and what’s the
> syntax? “# dos2unix filename”?

If you wrote them with kwrite, just run them. It’s extremely unlikely you’d
have any problems.


Hanlon’s Razor:
Never attribute to malice that which is
adequately explained by stupidity.

I tried that, and like I said, I get the bad interpreter permission denied error. There is no new line at the end, not sure if there’s any difference there. And as this script basically makes it run the ut2004-bin program, I tried opening it directly, no luck. Permission denied, even if I try to do that as root!

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Yup… that’s it.

Try the following:

/bin/bash /path/to/your/script

Good luck.

GreatEmerald wrote:
> I made the script by a copy-paste to KWrite. That messes it too? And do
> I need anything else than Bash for the dos2unix command, and what’s the
> syntax? “# dos2unix filename”?
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIxWMR3s42bA80+9kRAgZiAJoDE4Bs92bM+Xd7NYdktoXsDaE3VACghyEB
Ql5G4RZVfWMkHXUZCjQmAPc=
=sLW8
-----END PGP SIGNATURE-----

Yes! It works! Thanks!
Now how do I make that into a symlink in /usr/bin so I could start it by just typing in ut2004? Or will I have to always type /bin/bash ut2004?