Search code examples
linuxshellkde-plasmafedora-25

Can I execute commands written in a textdocument in the terminal


This may be a very simple question, but after switching from windows to linux (and being forced to use the shell way... way more often than I was forced with windows), there is still much new stuff to learn for me.

I am using fedora 25 on my laptop as my "surf and work" system. So I wanted to install Spotify, to be able to listen to music.

To install the software, I have to execute 4 commands:

1. Add the Spotify repository signing key to be able to verify downloaded packages

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys BBEBDCB318AD50EC6865090613B00F1FD2C19886

2. Add the Spotify repository

echo deb http://repository.spotify.com stable non-free | sudo tee /etc/apt/sources.list.d/spotify.list

3. Update list of available packages

sudo apt-get update

4. Install Spotify

sudo apt-get install spotify-client

My Question: Can I write these commands into a textdocument and execute them as a script?

I tried it with chmod, but I just don´t get it working right. I used this link as help (yes, I am from germany ^^)


Solution

  • Create a file whose first line is:

    #!/bin/sh
    

    Then put the commands after that.

    Add execute permission to the file:

    chmod +x filename
    

    Then run the script as:

    ./filename