Skip to content

Commit 91bcde9

Browse files
authored
Merge branch 'master' into iphone-photos-transfer
2 parents 11cb4f0 + 92835da commit 91bcde9

13 files changed

+262
-33
lines changed

content/bash-scripting-basics.md

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
---
2+
title: Bash Scripting Basics
3+
description: >
4+
Creating scripts using Bash.
5+
keywords:
6+
- bash
7+
- script
8+
9+
facebookImage: /_social/article
10+
twitterImage: /_social/article
11+
12+
hidden: false
13+
section: about-your-os
14+
tableOfContents: true
15+
---
16+
17+
We will be writing a script for [BASH (Bourne Again Shell)](https://en.wikipedia.org/wiki/Bash_(Unix_shell)). There are many different languages and tools to create scripts for your tasks. Some languages are better suited for specific tasks than others. Bash is a great starting point, as it uses the same language as your built in terminal commands that already exist in your Linux OS.
18+
19+
**NOTE:** This tutorial assumes you are running Pop!_OS or Ubuntu, but the script will work on any Linux/Unix OS with Bash.
20+
21+
## Creating a working script
22+
23+
There are 2 important details for writing a Bash script that make it functional. The first is called the [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)). The shebang tells your OS what scripting language is being used (in this case, we are using Bash). The shebang is usually the first line in the script.
24+
25+
Open your text editor of choice (I will be using <u>gedit</u>, as it comes with Pop!_OS by default). In the text editor, add the following line to as the very first line in your script:
26+
27+
```
28+
#!/usr/bin/env bash
29+
```
30+
31+
The line above is the shebang. There are many ways to create scripts, and the shebang will be crucial for the OS to handle your script correctly.
32+
33+
Let's create a directory to save your scripts. This will keep your Home directory tidy, and also keep a dedicated place for things you are working on. In my case, I have chosen to create a directory named `scripts` in my Home directory. Next, let's save our script that we are writing to this newly created `~/scripts/` directory. You can name this script whatever you like, but for the sake of this tutorial, I am going to name this script `basics.sh`. Note that I gave the file a `.sh` extension. This is not necessary for the script to work, but it will help you as a user know that this is a Bash script because it ends with `.sh`. Other scripting languages use similar naming conventions (Python scripts end with `.py`, or LUA scripts end with `.lua`).
34+
35+
The second crucial detail for your OS to properly run your script is to make it executable. As of right now, your script is just a regular text file. In order for your OS to run your script, we will need to make this text file executable. This can be done by navigating to our `~/scripts/` directory with our File Manager. Once you locate your script file, right click on the file to bring up with context menu and select "Properties". This will bring up the various details about the file we are looking at. Click on the tab labelled "Permissions". There will be a checkbox labelled "Allow executing file as program". Make sure to check this box. Once this is enabled, the script will be able to run.
36+
37+
At the moment, the script will do nothing if we decided to execute it, so let's add some commands and then test our script. Open the script and add the following line below your first `shebang` line:
38+
39+
```bash
40+
echo "The script executed correctly."
41+
```
42+
43+
We can now attempt to run our script. Open the terminal from your Application Launcher. I am going to assume that you have followed along and created a directory in your Home directory called `scripts` and that you have named this script `basics.sh` (if you have placed it in a separate directory or named it differently, the steps are the same, but you must substitute the file names and paths). First, we need to navigate in our terminal to our `scripts` directory. Input the following command in your terminal to change directory to `~/scripts`:
44+
45+
```bash
46+
cd ~/scripts
47+
```
48+
49+
You can now run your script by running the following command in your terminal:
50+
51+
```bash
52+
./basics.sh
53+
```
54+
55+
If it worked, your terminal should output the following line:
56+
57+
`The script executed correctly.`
58+
59+
Congratulations! You have created a working Bash script. Of course, outputting a single line does not provide much functionality, so we will be doing just that in the next section.
60+
61+
## Adding functionality
62+
63+
At this point, our script does one thing: It outputs a single line in our terminal. The script works, but it isn't very useful yet. There are many things you can do with a script, especially once you start combining several commands together. Here are some websites that can be helpful in the search for more commands:
64+
65+
- [Stack Overflow](https://stackoverflow.com)
66+
- [AskUbuntu](https://askubuntu.com)
67+
68+
Once you find commands that you want to add to your script, you can run them in a terminal to test them and see how they work.
69+
70+
It may also be helpful to read the *manual pages* (often shortened to "man pages") for commands that you're using. To view a command's manual page, simply run `man command` where "command" is substituted for the command you are looking up. To exit the manual page viewer, hit the `q` key.
71+
72+
### Variables
73+
74+
Let's start with asking the user for information like their name and favorite color. In order to output this information, we will need to first ask for this input, and then after it is input, we will store the information into a `variable`. Variables can hold values, and can be changed after the variable is created, so you can adjust values later on.
75+
76+
In our script file, we should have 2 lines already created: the shebang and our `echo` command that outputs a line. Let's change the `echo` command to match the "theme" of our script. Open the script in your text editor and edit the 2nd line with the `echo` command to ask the user for their First Name:
77+
78+
```bash
79+
echo "What is your first name?"
80+
```
81+
82+
Next, we will be using the `read` command to allow the user to input text. The text they enter will be stored in a variable that we can choose the name of. In this case, we will call the variable `firstName`. You can name the variable whatever you would like, but be sure to adjust your script accordingly. In our text editor, create a new line below our first `echo` command and input the following line:
83+
84+
```bash
85+
read firstName
86+
```
87+
88+
If we were to run our script in our terminal, it will first output a line that asks "What is your first name?". It will then sit and wait for the user to input text. Once the user inputs text and presses Enter, the script will end. We have not given the script any commands to use this information that the user has input. Let's add some output that shows what the user has typed in their terminal. Add a new line to your script:
89+
90+
```bash
91+
echo "Your first name is: $firstName"
92+
```
93+
94+
Notice that in order to use our `firstName` variable, we use the `$` in front of it. This will tell our terminal that we intend to use the variable called `firstName`. If I were to run the script, it will ask for my first name. I will input the name "Garrett", and the script will then output the following line:
95+
`Your first name is: Garrett`
96+
97+
Now, let's add another question to this script. This time, we will ask for the user's favorite color. We will then use the `read` command again to get user input and store it in a variable called `favoriteColor` and then finally output a sentence that shows what the user input:
98+
99+
```bash
100+
echo "What is your favorite color?"
101+
read favoriteColor
102+
echo "Your favorite color is: $favoriteColor"
103+
```
104+
105+
At this point, you should have a working script that asks the user for their name and their favorite color and then reacts to this information by outputting a sentence that reflects this information. The full script at this point should look like this:
106+
107+
```bash
108+
#!/usr/bin/env bash
109+
echo "What is your first name?"
110+
read firstName
111+
echo "Your first name is: $firstName"
112+
echo "What is your favorite color?"
113+
read favoriteColor
114+
echo "Your favorite color is: $favoriteColor"
115+
```
116+
117+
### If-Then Statements
118+
119+
Sometimes we want different things to happen depending on what inputs/variables are stored. For instance: if a file exists, then do *a*, but if the file does not exist, then do *b*. Or if a number is higher than *x* then do *a*, but if the number is lower than *x*, then do *b*. We can do this with an `if` statement.
120+
121+
For this, we will be asking the user to input a number. If the number is higher than *x* we will do *a*, but if the number is lower than *x*, we will do *b*.
122+
123+
Add a new line to your script. We will be making the target number 23, but you can pick any number you want. We will be putting the target number into a variable called `targetNumber`. Add the following line to your script:
124+
125+
```bash
126+
targetNumber=23
127+
```
128+
129+
We will now ask the user to input a number, and store that number to a variable called `guess`. Add the following lines to your script:
130+
131+
```bash
132+
echo "Guess the number:"
133+
read guess
134+
```
135+
136+
We now need to create and `if` statement to compare the `targetNumber` to the user input `guess` variable. The script will output different sentences depending on whether the user is too low, too high, or if they guess correctly. Add the following lines to your script:
137+
138+
```bash
139+
if [ $guess == $targetNumber ]
140+
then
141+
echo "You guessed the correct number!"
142+
elif [ $guess -lt $targetNumber ]
143+
then
144+
echo "You guessed lower than the target number."
145+
elif [ $guess -gt $targetNumber ]
146+
then
147+
echo "You guessed higher than the target number."
148+
else
149+
echo "Something went wrong."
150+
fi
151+
```
152+
153+
If you run the script, it will ask the user for their name and their favorite color. It will then ask the user to input a number. After the user inputs the number, depending on whether it was lower, higher or correct, the script will dynamically adapt to the user input.
154+
155+
## Conclusion
156+
157+
Bash scripting can be very useful in many different cases. I use scripting to automatically create a new work note with the current date as the title of the note document. I also have scripts to open certain applications or change my desktop theme. I have developed scripts to convert audio files to a specific format, or fill out PDF documents quickly. There is a lot to learn, so don't get discouraged or frustrated. Try to keep at it. As you make mistakes, you will learn for the next script you write. There are so many resources to help with your project. I have listed a few places to help with this below.
158+
159+
## Useful places to find information
160+
161+
Scripting can get advanced and complicated very quickly. There are numerous resources online for tips, tutorials, and forums to get help. Here are a few places to find ideas:
162+
163+
- [GNU Bash Manual](https://www.gnu.org/software/bash/manual/bash.html)
164+
- [Pure BASH Bible - Dylan Araps](https://github.com/dylanaraps/pure-sh-bible)
165+
- [Free Code Camp - Bash Scripting](https://www.freecodecamp.org/news/bash-scripting-tutorial-linux-shell-script-and-command-line-for-beginners/)

content/before-you-open-a-support-ticket.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ This article combines several self-help articles resolving common issues experie
2626

2727
### 1. Do you have a current backup of your files?
2828

29-
If your issue is time-sensitive, reinstalling the or [refreshing](/articles/pop-recovery#refresh-install) operating system may provide the fastest resolution. Be sure to backup all important data before performing any tests or contacting Support. Re-imaging is much easier to do if we know that your important files are safe.
29+
If your issue is time-sensitive, reinstalling or [refreshing](/articles/pop-recovery#refresh-install) the operating system may provide the fastest resolution. Be sure to back up all important data before performing any tests or contacting Support. Re-imaging is much easier to do if we know that your important files are safe.
3030

3131
**Note**: This guide may cover diagnostics and testing that you've already performed. Skip those sections as needed, but be sure to provide that information when submitting your ticket.
3232

content/desktop-environment.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Pop!\_OS and Ubuntu both include the GNOME desktop environment by default. A des
2323

2424
You can install an alternative desktop environment using the instructions below.
2525

26-
**NOTE:** be careful when installing other desktop environments, as they may affect the default GNOME desktop (both Ubuntu and Pop).
26+
> **Warning:** Installing other desktop environments may affect the visual style and functionality of the default GNOME desktop (on both Ubuntu and Pop!_OS).
2727
2828
If you run into trouble while using an alternative desktop environment, you may wish to revert to the default environment. To ensure the default GNOME desktop environment is installed in Pop!\_OS, install the `pop-desktop` package:
2929

@@ -229,14 +229,16 @@ gsettings set org.cinnamon.desktop.lockdown disable-lock-screen false
229229

230230
### Removing Desktop Environments
231231

232-
If you no longer want to use a desktop environment, it can be removed by using:
232+
If you no longer want to use a desktop environment, it can be removed by using the `sudo apt autoremove --purge` command with the name of the package you originally installed. For example, if you installed LXDE with `sudo apt install lxde`, you can remove it using the following command:
233233

234234
```bash
235-
sudo apt autoremove --purge ...
235+
sudo apt autoremove --purge lxde
236236
```
237237

238-
For example, to remove KDE:
238+
Some desktop environments (such as KDE) may leave behind additional packages even after uninstalling the original package with the `autoremove` command. To more thoroughly remove packages related to a desktop environment, use a regular expression to remove all packages beginning with the name of the environment followed by a hyphen (for example, `kde-`):
239+
240+
> **Warning:** Because regular expressions can match packages you don't expect, inspect the list of packages being removed before confirming the operation, and be prepared to reinstall any packages you wish to keep afterwards.
239241
240242
```bash
241-
sudo apt autoremove --purge kde-standard
243+
sudo apt autoremove --purge 'name?(^kde-)'
242244
```

content/difference-between-pop-ubuntu.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ With encryption enabled by default, and reporting through Ubuntu disabled, Pop!\
4747

4848
## Custom Keyboard Shortcuts
4949

50-
After conducting a study of Ubuntu and GNOME keyboard shortcuts, we decided to make some shortcuts more efficient for common user behaviors. The shortcut for switching workspaces, for example, is <kbd>Super</kbd> + <kbd>Arrow</kbd> <kbd>Up</kbd> or <kbd>Down</kbd>.
50+
After conducting a study of Ubuntu and GNOME keyboard shortcuts, we decided to make some shortcuts more efficient for common user behaviors. The shortcut for switching workspaces, for example, is <kbd>Super</kbd> + <kbd>Ctrl</kbd> + <kbd>Arrow</kbd> <kbd>Up</kbd> or <kbd>Down</kbd>.
5151
[See all keyboard shortcuts](/articles/pop-keyboard-shortcuts/)
5252

5353
## Default Apps: Slimming down on bloatware

content/fix-pvpn-killswitch.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,15 @@ tableOfContents: true
2121

2222
ProtonVPN's kill switch will disable internet connectivity when you are not connected to a VPN server. This ensures the true IP address if your computer is never leaked to the internet. If the kill switch is set to `Permanent`, then your computer will be unable to connect to the internet, even if ProtonVPN isn't running (i.e., at system start up), the GUI application becomes inaccessible, or if ProtonVPN was improperly removed from the system.
2323

24-
![ProtonVPN Kill Switch](images/fix-pvpn-killswitch/proton-killswitch.png)
24+
![ProtonVPN Settings](images/fix-pvpn-killswitch/ProtonVPN-Settings.png)
2525

26-
> ℹ️ ProtonVPN installs to the entire system; not just for a single user. If ProtonVPN is installed under another user account and has the kill switch enabled, other users will not be able to connect to the internet until ProtonVPN connects to a server.
26+
![ProtonVPN Kill switch](images/fix-pvpn-killswitch/ProtonVPN-Killswitch.png)
27+
28+
> **NOTE:** ProtonVPN installs to the entire system; not just for a single user. If ProtonVPN is installed under another user account and has the kill switch enabled, other users will not be able to connect to the internet until ProtonVPN connects to a server.
29+
30+
<!-- v4 of ProtonVPN does not have a CLI version like v3 did per this support article: https://protonvpn.com/support/linux-vpn-setup/
31+
32+
We can enable this again (with new option(s) as needed when it is available again) .
2733
2834
## ProtonVPN GUI Application is Inaccessible
2935
@@ -33,6 +39,8 @@ If the ProtonVPN GUI application suddenly becomes inaccessible, but you still ha
3339
protonvpn-cli ks --off
3440
```
3541
42+
-->
43+
3644
## Permanent Kill Switch Persists After System Refresh
3745

3846
Pop!\_OS's [Refresh Install](/articles/pop-recovery) feature is a convenient tool for recovering a broken installation while preserving some of the user's data.

content/media-production-on-pop.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ keywords:
1313
- LMMS
1414
- GIMP
1515
- Flowblade
16+
- Shotcut
1617

1718
facebookImage: /_social/article
1819
twitterImage: /_social/article
@@ -89,8 +90,16 @@ Install Directly From the Pop!\_Shop
8990

9091
Krita is a free and open source raster graphics editor that is primarily focused on digital drawing and painting. It features an OpenGL-accelerated canvas, non-destructive layers and masks, an advanced brush engine, and support for many drawing tablets.
9192

93+
Install Directly From the Pop!_Shop
94+
9295
### Flowblade
9396

9497
Flowblade is a multitrack non-linear video editor with a set of industry standard editing tools suitable for beginners and masters alike to help make your vision a reality of image and sound.
9598

96-
Install Directly From the Pop!\_Shop
99+
Install Directly From the Pop!_Shop
100+
101+
### Shotcut
102+
103+
Shotcut is a free, open source, cross-platform video editor. It has wide format support, various device and transport options, and an intuitive but customizable user interface.
104+
105+
Install Directly From the Pop!_Shop

0 commit comments

Comments
 (0)