Forum › Forums › New users › New Users and General Questions › Can’t run most .sh bash scripts from spaceFM
- This topic has 27 replies, 4 voices, and was last updated Sep 14-9:10 pm by PenguinGuy.
-
AuthorPosts
-
September 9, 2021 at 9:20 pm #66822Member
PenguinGuy
Hi,
Most of my .sh scripts will not run on click other than ‘code –disable-gpu’ to open VS Code or ‘echo some_text’.
Also, it will not open a Terminal window at all with execute (my scripts are coded to keep the window open). If I use the spacefm ‘choose’ roxterm it opens a terminal without running the script.
The only terminal I can open & run them in is ‘Terminal’ & they will usually fail with ‘command not found’ or ‘: command not foundgs’
The drive has exec & can run some scripts on it like the VS Code one above — permissions are full rwx-rwx-rwx, owner is root:root (although I had the same problems with user:user).
Also, adding ‘#!/bin/sh’ or ‘#!/bin/bash’ causes a dialog error of the script not being found.
Adding an extra line at the end in Geany or removing it in Leafpad seem to make no difference.
Any ideas?
================================================================
Example: installing & testing nvm from https://github.com/nvm-sh/nvm
A simple version check command works if entered into the terminal, but not in the .nh:
https://i.postimg.cc/bzxSY8c7/nvm00.jpg
- This topic was modified 1 year, 7 months ago by PenguinGuy.
- This topic was modified 1 year, 7 months ago by PenguinGuy.
- This topic was modified 1 year, 7 months ago by PenguinGuy.
September 10, 2021 at 8:20 am #66845Member
sybok
::Hi,
I am not 100% sure I understand your post, thus my reply may not be an answer that clarifies/solves your problem.
If if does not, please provide minimal working and non-working examples for me/others to test.
Also, I have never attempted to run binaries from spacefm, I am more of a keyboard (CLI/terminal/keyboard-shortcuts) type.CODING EXPERIENCE/PRACTICE:
I always start scripts I want to call directly (no imports or via other scripts) with the ‘#’ symbol followed by the appropriate binary OR I call them with explicit specification of the binary/interpreter.
That works as my below examples (Case I, 1.B) + 2.B) and Case II, 1.A) + 2.A)) demonstrate.EXAMPLE (CALLED FROM TERMINAL):
I created some simple scripts (as standard user) and I have attempted to call them from terminal:
1) hello1[ab].sh#!/bin/sh echo "Hello2) hello2[ab].sh
echo "Hello"The permissions are following:
ls -lh hello*.sh -rw-r--r-- 1 ... hello1a.sh -rwxr--r-- 1 ... hello1b.sh -rw-r--r-- 1 ... hello2a.sh -rwxr--r-- 1 ... hello2b.shi.e. the 1b) and 2b) are executable.
I) Calling from terminal as: ‘./<scriptname>’
1.A) + 2.A): Error “Permission denied”
1.B) + 2.B): “Hello” as expectedII) Calling from terminal as: ‘bash <scriptname>’ <– the “interpreter” explicitly specified
1-2.A) + 1-2.B): Print “Hello”Scripts called without elevated permissions (no root/sudo) from my ‘/home’ which is mounted as follows (according to ‘/etc/fstab’):
UUID=... /home ext4 defaults,noatime 1 2According to man-page of mount, ‘defaults’ is equivalent to: rw, suid, dev, exec, auto, nouser.
‘exec’ means that the executable files can be executed.DRIVE/PARTITION PERMISSIONS:
There was another post on the forum that revealed that ‘auto’ was used in mount and it set the permissions not to run executable files (‘noexec’) by default but explicit calling from terminal such as
sh <scriptname>
worked well.- This reply was modified 1 year, 7 months ago by sybok. Reason: Close all tags
September 10, 2021 at 9:00 am #66848Member
Xecure
::I am with sybok. Not sure what is the exact problem.
To run a .sh script, you need 2 conditions:
A. The script must have a shebang
for example:, for bash
#!/bin/bashB. The file with the script must have executable permission. In spacefm, right the file to see the context menu, and move to Properties > Permissions. Set executable permissions for the file.
Specific to spacefm, once a file has the above conditions, right-clicking and selecting “Execute” will run the script.
If you want it to be single/double click to run the script directly, in the Spacefm’s top menus, go to View > Preferences > Interface, and enable “Click runs executables”. From then on, you will have that set as the default behavior for executables in SPacefm.I prefer opening the script in the editor as the default behavior (to avoid possible problems when my mouse decides to double click on a file when I was just trying to select it), but others prefer to click on scripts to execute them automatically.
Example of very stupid script I made for you to test (confirmed to work here):
#!/bin/bash TEXT="Do you want to count to 10?\n it will save them in $HOME/counting" TITLE="Counting to 10" yad --tittle="$TITLE" --text="$TEXT" --center --borders=10 if [ $? -eq 0 ]; then COUNTER=1 rm "$HOME/counting" while [ $COUNTER -le 10 ]; do echo "COUNTING: $COUNTER" >> "$HOME/counting" COUNTER="$((COUNTER+1))" done else echo "Not counting." fiantiX Live system enthusiast.
General Live Boot Parameters for antiX.September 10, 2021 at 3:53 pm #66856Anonymous
::permissions are full rwx-rwx-rwx, owner is root:root
read the manpage for the “chmod” command to learn more about permissions.
Next, read the manpage for the “chown command to understand the “something:something” (x_colon_y)I had the same problems with user:user
Does your system have a login account literally named “user”?
If not, it’s senseless to assign ownership to user:blahblah.
Senseless, but perhaps no harm, because :user ~~ by default, all login accounts are granted membership to the group named “user”rwx-rwx-rwx, owner is root:root
This assignment is seldom advisable. Non-root users should not be granted WRITE permissions for root -owned files, especially not root-owned executable files!
‘command not found’
In which directory do the to-be-executed scriptfiles reside?
Unless that directory is enumerated within your $PATH ( ref: ~/.profile ) …a shell interpreter will be blind to any commands within that directory.example scenario:
staring at a terminal command prompt “$/home/demo:”
If I have created a script “/home/demo/happy.sh” and have set it executable “chmod +x /home/demo/happy.sh”
The shell interpreter [probably] will be able to find/recognize and execute my script if I simply type “happy.sh” then press Enter.
However, if I “cd ~/Downloads” (or elsewhere)… as soon as the script’s parent directory is no longer the CWD (current working directory) of the shell interpreter… yes, typing just “happy.sh” would result in “command not found”it will not open a Terminal window at all with execute
WHAT will not open a terminal window? Are you referring to a “launched from file manager” operation?
If so, why do you expect a terminal window to open? I would expect the file manager will [by default] simply pass the call to the assigned shell interpreter, which in turn, will execute the script in a non-interactive shell. Consider: maybe “Run in terminal” (not “Execute”) — along with ensuring your scripts reside within a $PATH directory — would suit your expectation here.September 10, 2021 at 6:58 pm #66867Member
PenguinGuy
::Alright, updated the original post with an example & image.
WHAT will not open a terminal window? Are you referring to a “launched from file manager” operation?
If so, why do you expect a terminal window to open? I would expect the file manager will [by default] simply pass the call to the assigned shell interpreter, which in turn, will execute the script in a non-interactive shell. Consider: maybe “Run in terminal” (not “Execute”) — along with ensuring your scripts reside within a $PATH directory — would suit your expectation here.I expect the script terminal to stay open because many scripts have notes & feedback that needs to be displayed in a Terminal window. I do open -> Terminal to get a Terminal window. Not sure how to reassign the default click behavior in Spacefm — yes I have ‘Click runs executables’ checked in preferences, but that’s not the same thing as a different command.
I think the owner switched to root:root from user:user when I added myself to sudo group because I was getting annoyed with testing some other thing. No one uses this computer or files other than myself. Either that or the default antiX user is set to sudo for user group. I’ve changed it back & forth like 2 or 3 times so I can’t remember how it originally was.
- This reply was modified 1 year, 7 months ago by PenguinGuy.
- This reply was modified 1 year, 7 months ago by PenguinGuy.
- This reply was modified 1 year, 7 months ago by PenguinGuy.
September 10, 2021 at 7:49 pm #66874Member
Xecure
::nvm is a bad example. Which is the path to nvm? Is it $HOME/.nvm/? This is not a valid path for running from spacefm, from scripts, etc. ONLY from the user terminal. This is because it loads the path or alias or something else to your $HOME/.bashrc, so only the user’s bash, loaded in the terminal, will know of nvm’s existence.
if the script you created in your example is run like this:
./__nvm_-v.sh
does it run?Did you try any other script that uses system’s installed commands (like sybok or my script)? Do they work if it is in your linux persistence? And in your external drive? This would be a better test to see if you can run script at all from spacefm-
I expect the script terminal to stay open because many scripts have notes & feedback that needs to be displayed in a Terminal window. I do open -> Terminal to get a Terminal window.
I think by default, spacefm will execute the script and not launch it in terminal. You could create this “Run in terminal” option by:
right-click the script, and navigate the menu to Open > File Handlers…
Click an empty space in the left pane to start creating a new handler. Fill this out on the left pane
Name: Run in terminal
MIMEType: application/x-shellscript
Enable the option “Run in Terminal” in Open Command: and below enter this command
"$fm_file"
If you want this a the default behavior, leavte active the option “Enable as a default opener” (at the top).
Click Add on the left panel and you will have created this “Run in terminal” option. And the best of all, it will be the default option for all scripts (except if you select Open > Execute).Please test this out with other scripts you know work in default antiX before using custom scripts. It should now also run your __nvm_-v.sh script, as it will launch it in the user terminal (where the nvm command is recognized).
- This reply was modified 1 year, 7 months ago by Xecure.
antiX Live system enthusiast.
General Live Boot Parameters for antiX.September 10, 2021 at 10:48 pm #66884Member
PenguinGuy
::nvm is a bad example. Which is the path to nvm? Is it $HOME/.nvm/? This is not a valid path for running from spacefm, from scripts, etc. ONLY from the user terminal. This is because it loads the path or alias or something else to your $HOME/.bashrc, so only the user’s bash, loaded in the terminal, will know of nvm’s existence.
if the script you created in your example is run like this:
./__nvm_-v.sh
does it run?Did you try any other script that uses system’s installed commands (like sybok or my script)? Do they work if it is in your linux persistence? And in your external drive? This would be a better test to see if you can run script at all from spacefm-
I expect the script terminal to stay open because many scripts have notes & feedback that needs to be displayed in a Terminal window. I do open -> Terminal to get a Terminal window.
I think by default, spacefm will execute the script and not launch it in terminal. You could create this “Run in terminal” option by:
right-click the script, and navigate the menu to Open > File Handlers…
Click an empty space in the left pane to start creating a new handler. Fill this out on the left pane
Name: Run in terminal
MIMEType: application/x-shellscript
Enable the option “Run in Terminal” in Open Command: and below enter this command
"$fm_file"
If you want this a the default behavior, leavte active the option “Enable as a default opener” (at the top).
Click Add on the left panel and you will have created this “Run in terminal” option. And the best of all, it will be the default option for all scripts (except if you select Open > Execute).Please test this out with other scripts you know work in default antiX before using custom scripts. It should now also run your __nvm_-v.sh script, as it will launch it in the user terminal (where the nvm command is recognized).
This code still doesn’t work: ./__nvm_-v.sh — maybe something in the script with this might work?
I had to uncheck the ‘Click runs executables’ in SpaceFM preferences to get the Terminal window, but it still doesn’t work & looks identical to just choosing open in Terminal & setting at default (the middle Terminal in this image: https://i.postimg.cc/bzxSY8c7/nvm00.jpg). Although, thanks — I suspect this might come in handy in the future.
Also, I need to get some programming done in nvm so that’s why I chose it. I might have to switch back to Windows soon to get some actual work done.
September 11, 2021 at 6:35 am #66889Member
Xecure
::After installing nvm myself I can see that the command nvm doesn’t exists as a executable file, but that it is sourced from a nvm.sh file to be used from the terminal.
You will need to source it on every script you want to use nvm, at the top of the script before executing anything:#!/bin/bash # Exporting nvm export NVM_DIR="$HOME/.config/nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm nvm -v read -p "Press any key to continue"My tests:
https://ibb.co/80xvRkZantiX Live system enthusiast.
General Live Boot Parameters for antiX.September 11, 2021 at 3:14 pm #66913Member
PenguinGuy
::After installing nvm myself I can see that the command nvm doesn’t exists as a executable file, but that it is sourced from a nvm.sh file to be used from the terminal.
You will need to source it on every script you want to use nvm, at the top of the script before executing anything:#!/bin/bash # Exporting nvm export NVM_DIR="$HOME/.config/nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm nvm -v read -p "Press any key to continue"My tests:
https://ibb.co/80xvRkZThis makes sense, but it’s also the code added to the .bashrc upon installation. Are you sure something else can’t be added like . “~/bashrc” or elsewhere that calls this?
Like maybe antiX has a different path or bash config to enable this?
I tried:
. "$HOME/.bashrc"But I’m getting “shopt: not found” in the Terminal.
I created a __nvm_load.sh that I can path to that I guess basically does the same thing, but then it doesn’t go through the .bashrc
Thanks again.
- This reply was modified 1 year, 7 months ago by PenguinGuy.
- This reply was modified 1 year, 7 months ago by PenguinGuy.
- This reply was modified 1 year, 7 months ago by PenguinGuy.
September 11, 2021 at 3:57 pm #66918Member
Xecure
::nvm is meant to be used in interactive shells (opened by the user). They seem to recommend to always source ~/.nvm/nvm.sh at the beginning of every script.
See npm is only available in interactive shellSo, for any script that will use nvm, source it at the top of the file, or try something different so that any non-interactive shell can load it.
A dirty example would be to create a file in /usr/local/bin named “nvm”, make it executable, and have its contents be:
#!/bin/bash # Exporting nvm export NVM_DIR="$HOME/.config/nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm nvm "$@"Though, I would replace $HOME with the full path of your home folder (/home/Ransilon).
This creates an executable file available from any shell or program.antiX Live system enthusiast.
General Live Boot Parameters for antiX.September 11, 2021 at 4:12 pm #66922Member
PenguinGuy
::Well, I don’t want to do something quick n dirty that is hard coded or with hard coded paths (so it doesn’t work on other systems or machines).
This has never worked for me (there is no .nvm):
~/.nvm/nvm.shThis works though:
. "$HOME/.config/nvm/nvm.sh"Although, some scripts might require NVM_DIR…
- This reply was modified 1 year, 7 months ago by PenguinGuy.
- This reply was modified 1 year, 7 months ago by PenguinGuy.
September 11, 2021 at 4:58 pm #66925Member
Xecure
::This has never worked for me (there is no .nvm):
~/.nvm/nvm.shThis works though:
. "$HOME/.config/nvm/nvm.sh"Although, some scripts might require NVM_DIR…
Sorry. This was the path(~/.nvm/nvm) where nvm installed for me when running the install script. I assumed it was the default path. I didn’t mean to give you the wrong path.
Well, I don’t want to do something quick n dirty that is hard coded or with hard coded paths (so it doesn’t work on other systems or machines).
Then you will have to use a scripting language that can be read and works on other systems, if your intention is for the script to run universally.
The problem with nvm is that it will install on different places depending on the computer (as we just saw between our system and mine), so that issue you will need to figure out or see if the nvm documentation has any info for you.antiX Live system enthusiast.
General Live Boot Parameters for antiX.September 11, 2021 at 6:39 pm #66935Member
PenguinGuy
::This has never worked for me (there is no .nvm):
~/.nvm/nvm.shThis works though:
. "$HOME/.config/nvm/nvm.sh"Although, some scripts might require NVM_DIR…
Sorry. This was the path(~/.nvm/nvm) where nvm installed for me when running the install script. I assumed it was the default path. I didn’t mean to give you the wrong path.
Well, I don’t want to do something quick n dirty that is hard coded or with hard coded paths (so it doesn’t work on other systems or machines).
Then you will have to use a scripting language that can be read and works on other systems, if your intention is for the script to run universally.
The problem with nvm is that it will install on different places depending on the computer (as we just saw between our system and mine), so that issue you will need to figure out or see if the nvm documentation has any info for you.I’m just going to consider nvm done for now unless anyone has any other ideas.
Do you have any idea why I similarly can’t call ‘sudo nvidia-settings’ from a .sh either (I’m using the MX driver)?
It works from a terminal, Task Manager doesn’t give a path or any other hints. Is there some other path that has to sourced?
When I do a search I can find a ‘nvidia-settings.desktop’ in ‘usr/lib/nvidia/current’. If I source that path it doesn’t do anything though.
If I try ‘bash nvidia-settings’ in the Terminal I get ‘/usr/bin/nvidia-settings: cannot execute binary file’.
- This reply was modified 1 year, 7 months ago by PenguinGuy.
- This reply was modified 1 year, 7 months ago by PenguinGuy.
September 11, 2021 at 6:47 pm #66938Member
PenguinGuy
::Thanks, I’m just going to consider nvm done for now unless anyone has any other ideas.
Do you have any idea why I similarly can’t call ‘sudo nvidia-settings’ from a .sh either (I’m using the MX driver)?
It works from a terminal, Task Manager doesn’t give a path or any other hints. Is there some other path that has to sourced?
When I do a search I can find a ‘nvidia-settings.desktop’ in ‘usr/lib/nvidia/current’. If I source that path it doesn’t do anything though.
If I try ‘bash nvidia-settings’ in the Terminal I get ‘/usr/bin/nvidia-settings: cannot execute binary file’.
- This reply was modified 1 year, 7 months ago by PenguinGuy.
September 11, 2021 at 6:53 pm #66940Member
Xecure
::For nvm, if you create a script in /usr/local/bin/nvm containing:
#!/bin/bash # Exporting nvm export NVM_DIR="$HOME/.config/nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm nvm "$@"it should work for setting a fake executor for nvm which can be found by any script. When you no longer need it, you can remove it entirely without worry.
For nvidia settings, better use the full path. You can get the full path if you run in terminal
command -v nvidia-settingsI don’t know where it may be stored, but for the scripts, it is always recommended to use the full path to the executable. In your example
sudo /path/to/nvidia-settings
If the path is /usr/bin/nvidia-settings
sudo /usr/bin/nvidia-settings- This reply was modified 1 year, 7 months ago by Xecure.
antiX Live system enthusiast.
General Live Boot Parameters for antiX. -
AuthorPosts
- You must be logged in to reply to this topic.