T
Termux8mo ago
jezza444

bash: ./filename: Permission Denied

Hello all i have this problem after i successfully compiled main.cpp with clang as per the screenshot below. I have done termux-setup-storage, and as you can also see placed the .cpp file in com.termux/files/home. (In my internal storage, my tablet don't support Sdcard) You can also see the .stat of filename.
No description
4 Replies
fisher
fisher8mo ago
internal storage doesnt support execution, move your stuff to /data/data/com.termux/files/home/ or ~ for short also read this for how to edit files in there: !tag saf bot ded
Snipe scope
Snipe scope8mo ago
chmod +x filename Then try running it
guythatcreatesrandomstuff
!tag saf
Bonjour
Bonjour5mo ago
I know it's kinda weird thar I am replying after 3/4 months but whatever I just wanted to give you a quick solution. but first, I am assuming you know how to use a text editor in termux. if you don't, you may check a tutorial or something then read the rest of this comment. #!bin@fish said that you need to do it in the termux home file, but let's be realistic we all wanna run bash in the coding folder we made (whether it's in the internal storage or sd card) so, the best way to do it is by adding a command "run" that runs your little script no matter where it is. So, do the following:
nano /data/data/com.termux/files/usr/etc/bash.bashrc"
nano /data/data/com.termux/files/usr/etc/bash.bashrc"
this will open the bash.bashrc, which runs commands automatically the moment you open termux, in a text editor called nano. Termux has this text editor pre-installed afak but if you have another text editor you may also use it. after you open it, go to the bottom and add the following new commands:
alias bedit="nano /data/data/com.termux/files/usr/etc/bash.bashrc"

function run(){
if [[ "x${1}" == "x" ]]
then
echo "Please pass the name of a file"
return 1
fi

if [[ -d $1 ]]
then
echo "This is a directory. Please input a file"
return 1
fi

if [[ ! -f $1 ]]
then
echo "File doesn't exist"
return 1
fi

FIRST_PARAM="${1}"
DEFAULT_LOCATION=$PWD
TERMUX_LOCATION=/data/data/com.termux/files/home
BASHFILE_LOCATION="${TERMUX_LOCATION}/${FIRST_PARAM##*/}"
CURRENT_FILE_LOCATION="${DEFAULT_LOCATION}/${FIRST_PARAM##*/}"

chmod +x $1
mv $1 $TERMUX_LOCATION
chmod +x $BASHFILE_LOCATION
/$BASHFILE_LOCATION;echo
mv $BASHFILE_LOCATION $DEFAULT_LOCATION

if [[ $CURRENT_FILE_LOCATION != $(realpath $1) ]]
then
mv $CURRENT_FILE_LOCATION $1
fi
}
alias bedit="nano /data/data/com.termux/files/usr/etc/bash.bashrc"

function run(){
if [[ "x${1}" == "x" ]]
then
echo "Please pass the name of a file"
return 1
fi

if [[ -d $1 ]]
then
echo "This is a directory. Please input a file"
return 1
fi

if [[ ! -f $1 ]]
then
echo "File doesn't exist"
return 1
fi

FIRST_PARAM="${1}"
DEFAULT_LOCATION=$PWD
TERMUX_LOCATION=/data/data/com.termux/files/home
BASHFILE_LOCATION="${TERMUX_LOCATION}/${FIRST_PARAM##*/}"
CURRENT_FILE_LOCATION="${DEFAULT_LOCATION}/${FIRST_PARAM##*/}"

chmod +x $1
mv $1 $TERMUX_LOCATION
chmod +x $BASHFILE_LOCATION
/$BASHFILE_LOCATION;echo
mv $BASHFILE_LOCATION $DEFAULT_LOCATION

if [[ $CURRENT_FILE_LOCATION != $(realpath $1) ]]
then
mv $CURRENT_FILE_LOCATION $1
fi
}
this will add 2 new commands you may use. bedit Use it to open the bash.bashrc file in nano. run use it to fix your issue
run ./filename
run ./filename
or
run filename
run filename
or
run /storage/emulated/0/MYCODE/C_CODE/PROJECT1/filename


# replace /storage/emulated/0/MYCODE/C_CODE/PROJECT1/filename with the actual path
run /storage/emulated/0/MYCODE/C_CODE/PROJECT1/filename


# replace /storage/emulated/0/MYCODE/C_CODE/PROJECT1/filename with the actual path
---- also, if you don't want to use nano in bedit just replace the "nano" in the beginning of the code I gave you with your desired text editor
Want results from more Discord servers?
Add your server