0

I was making this bash install script on ubuntu 21.10. I was going to test out the first little bit, but I ran into this error.

/tmp/geany_run_script_GBYCG1.sh: 7: ./install sauerbraten 2020: Permission denied

(program exited with code: 126) Press return to continue

This is the script so far.

#!/bin/bash

DIRECTORY="$(dirname "$(dirname "$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )")")"

function error { echo -e "\e[91m$1\e[39m" exit 1 }

wget https://sourceforge.net/projects/sauerbraten/files/sauerbraten/2020_11_29/sauerbraten_2020_12_29_linux.tar.bz2/download

#tar -xf

What is wrong, and how can I fix it?

  • The DIRECTORY= line is completely bonkers. I can't even understand what you're trying to achieve there. And it has too many quote signs. Quote signs are not like parenthesis - every pair of consecutive quotes are closing one string between them. So for instance, your second quotes are closing the first quotes, they don't start a new pair (like I think that you think they should do). But again, I'm having trouble to follow what you're even trying to do. – aviro Jan 18 '22 at 21:29
  • 2
    @aviro Double quotes inside $(...) are parsed separately from those outside. So the OP is hoping that $0 reflects the path to the current script. The innermost $(..) prints the "physical" location of the script, and the each of the other two $(..) go up one directory level. – icarus Jan 18 '22 at 21:41
  • 2
    @aviro, actually, with the command substitutions there, they do need the quotes on each level. It's not that the quotes nest like parentheses, but the command substitutions do, and the quotes inside and outside the command substitution are independent. See e.g. https://unix.stackexchange.com/q/443989/170373 – ilkkachu Jan 18 '22 at 21:42
  • @ilkkachu the error is not from the posted script I think - it's from a kind of wrapper script that geany is creating on-the-fly to execute it. Probably the OP needs to configure a geany "build" command for shell scripts – steeldriver Jan 18 '22 at 22:26
  • ... so it looks like they just need to make their script ./install\ sauerbraten\ 2020 executable – steeldriver Jan 18 '22 at 22:37
  • @steeldriver, right, I assumed that the script shown was geany_run_script_GBYCG1.sh, without realizing it was in /tmp/... But yeah, if the script shown is ./install sauerbraten 2020, then it's probably just a chmod needed on that. – ilkkachu Jan 18 '22 at 22:58
  • 1
    @ilkkachu yeah I just had a play with geany on my box to confirm – steeldriver Jan 18 '22 at 22:59
  • @steeldriver, good job. – ilkkachu Jan 18 '22 at 23:03
  • the directory line was from a thing that was about "how to make a bash install script" – Random Linux User Jan 19 '22 at 17:58

1 Answers1

2

The error is not from your bash script, it's from the shell wrapper script that Geany uses to execute your file (when you press F5 or select the Build -> Execute menu item).

The default Geany Execute action is "./%f" which takes the name of your file and wraps it in a script in /tmp like

#!/bin/sh

rm $0

cd '/home/username'

"./name of your file"

echo "


(program exited with code: $?)"

echo "Press return to continue" #to be more compatible with shells like dash dummy_var="" read dummy_var

The error is coming from Line 7 of this script, i.e.

"./name of your file"

and is simply indicating that file ./install sauerbraten 2020 cannot be executed because of its permission bits - likely the executable bit is not set for your user. You can fix it with

chmod +x "./install sauerbraten 2020"
steeldriver
  • 81,074