0

I create a test shell script in my Desktop directory, make it executable and it runs OK. I copy it to a mounted SD chip and the attributes change and execution fails.

Here is a test example. Note the command prompt is the working directory. It was slightly edited (added blank lines and deleted some prompts) for clarity.

I don't understand why the attributes change and why the script fails.

## print file test.sh contents
Desktop>>  cat test.sh    
#!/bin/bash                    
echo 'Works OK'
Desktop>>

## list file attributes to verify it is executable. 
##Note attributes. They change after file copy.
Desktop>>  ls -al test.sh                           
-rwxr-xr-x. 1 ron ron 28 Feb 16 13:41 test.sh       
Desktop>>

## run the shell
## shell output is correct.
Desktop>>  ./test.sh                                
Works OK 
Desktop>>

## copy shell to SD chip
Desktop>>  cp test.sh /media/removable/10-EDC/org   
Desktop>>

## change to SD chip 
Desktop>>  cd /media/removable/10-EDC/org
org>>

##list file attributes. Note that they have changed.
## org>>  ls -al test.sh                               
-rwxrwxrwx. 1 ron ron 28 Feb 16 14:58 test.sh
org>>

## run the shell. Fails.
org>>  ./test.sh                                    
bash: ./test.sh: Permission denied
org>> 

OS is Ubuntu 16.04.

It has been suggested that it may have something to do with the way the SD chip was formatted. I believe it is formatted as msdos (fat??) for compatibility with other machines. I have no experience in this (formatting issues) area.

Any assistance appreciated.

1
1

It depends how the SD card is mounted. A mount option is "noexec", which forbids execution of everything on the mounted device. So please check your mount options using mount (without parameters)(mount | grep media may restrict the output to your SD Card).

And yes, if the device is formatted for VFAT (as usual for SD cards, unless they are meant for a Raspberry), it won't support the User/Group/Other access flags not the Exec flag, so how these are handled is directed by mount options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.