Search code examples
linuxbashlinux-mint

Run applications with bash from Linux Mint


I started learning Bash on Mint Linux. The thing is I want to know how to open and execute programs. I have a test.sh in my junk directory so that I can mess around but when ever I type in gnome-open test.sh it just opens the file and not actually run it. In the test.sh file I have echo hi in there so that I can see that it worked and I gave the file the permissions for it to be an executable file so it should execute.


Solution

  • You need to do two things:

    1. Give the file execution permission (+x)
    2. Execute the file

    First you give the file permission no 755:

    chmod 755 test.sh
    

    Then you start it:

    ./test.sh
    

    The dotslash means "current directory", it's like saying c:\file.bat if \ is the current directory. You need that because the current dir (called PWD) is not in your PATH variable which means that you either need to specify the complete path, eg. /users/user/file.sh or using the dot which is a shortcut for the current directory.

    The file permission number 755 means:

    owner: 7 (read, write, exec)
    group: 5 (read, exec)
    other: 5 (read, exec)
    

    If you want to be the only one to be able to even open the file you may specify 700 instead. There are plenty of combinations, but 755 is most commonly used for scripts.

    edit:

    I forgot to mention that you need the dotslash everytime you run the script, but you only need to issue the chmod command once for every file.