You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lessons/07_permissions_and_environment_variables.md
+24-24Lines changed: 24 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ Approximate time: 40 minutes
10
10
11
11
- Grant or restrict access to files on a multi-user UNIX system
12
12
- View "Environment Variables" in Shell
13
-
- Describe the $PATH variable and how to append it
13
+
- Describe the ${PATH} variable and how to append it
14
14
15
15
## Permissions
16
16
@@ -217,28 +217,28 @@ $ env
217
217
218
218
It's a pretty long list! **In the context of the shell the environment variables are usually all in upper case.**
219
219
220
-
In this lesson, we are going to focus on two most commonly encountered environment variables: `$HOME` and `$PATH`.
220
+
In this lesson, we are going to focus on two most commonly encountered environment variables: `${HOME}` and `${PATH}`.
221
221
222
-
*`$HOME` defines the full path for the home directory of a given user.
223
-
*`$PATH` defines a list of directories to search in when looking for a command/program to execute.
222
+
*`${HOME}` defines the full path for the home directory of a given user.
223
+
*`${PATH}` defines a list of directories to search in when looking for a command/program to execute.
224
224
225
-
Environment variables, in most systems, are called or denoted with a "$" before the variable name, just like a regular variable. Let's use the `echo` command to see what is stored in `$HOME`:
225
+
Environment variables, in most systems, are called or denoted with a "$" before the variable name, just like a regular variable. Like regular variables, we can also wrap them in `{}` in order to be more explicit about the variable name. Let's use the `echo` command to see what is stored in `$HOME`:
226
226
227
227
```bash
228
-
$ echo$HOME
228
+
$ echo${HOME}
229
229
```
230
230
231
-
You should see the path to your home directory. `$HOME` can be used instead of the `~` (if you want to type 4 more characters).
231
+
You should see the path to your home directory. `${HOME}` can be used instead of the `~` (if you want to type 4 more characters).
232
232
233
233
234
234
`$HOME` is pretty straightforward, how about we take a look at what is stored in the `$PATH` variable:
This output is a lot more complex! Let's break it down. When you look closely at the output of `echo $PATH`, you should a list of full paths separated from each other by a ":".
241
+
This output is a lot more complex! Let's break it down. When you look closely at the output of `echo ${PATH}`, you should a list of full paths separated from each other by a ":".
242
242
243
243
Here is the list of paths in a more readable format:
244
244
*`/n/cluster/bin`
@@ -261,15 +261,15 @@ Each of these paths are referring to a directory, in this case a lot of them are
261
261
262
262
These are the directories that the shell will look through (in the same order as they are listed) for any given command or executable file that you type on the command prompt.
263
263
264
-
For example, we have been using the `ls` command to list contents in a directory. When we type `ls` at the command prompt, the shell searches through each path in `$PATH` until it finds an executable file called `ls`. So which of those paths contain that executable file?
264
+
For example, we have been using the `ls` command to list contents in a directory. When we type `ls` at the command prompt, the shell searches through each path in `${PATH}` until it finds an executable file called `ls`. So which of those paths contain that executable file?
265
265
266
266
For any command you execute on the command prompt, you can find out where the executable file is located using the `which` command.
267
267
268
268
```bash
269
269
$ which ls
270
270
```
271
271
272
-
What path was returned to you? Does it match with any of the paths stored in `$PATH`?
272
+
What path was returned to you? Does it match with any of the paths stored in `${PATH}`?
273
273
274
274
275
275
Try it on a few of the basic commands we have learned so far:
@@ -286,35 +286,35 @@ $ ls -lF /usr/bin/
286
286
287
287
The path `/usr/bin` is usually where executables for commonly used commands are stored.
288
288
289
-
> As pointed out earlier, a lot of the folders listed in the `$PATH` variable are called `bin`. This is because of a convention in Unix to call directories that contain all the commands (in ***binary*** format) **`bin`**.
289
+
> As pointed out earlier, a lot of the folders listed in the `${PATH}` variable are called `bin`. This is because of a convention in Unix to call directories that contain all the commands (in ***binary*** format) **`bin`**.
290
290
291
291
***
292
292
293
293
**Exercise**
294
294
295
-
Are the directories listed by the `which` command within `$PATH`?
295
+
Are the directories listed by the `which` command within `${PATH}`?
296
296
297
297
<details>
298
298
<summary><b><i>Answer</i></b></summary>
299
-
It should be. For example, if you would like to check the directory of command <code>pwd</code> - the output for <code>which pwd</code> is <code>/usr/bin/pwd</code>, and <code>/usr/bin</code> is within $PATH.
299
+
It should be. For example, if you would like to check the directory of command <code>pwd</code> - the output for <code>which pwd</code> is <code>/usr/bin/pwd</code>, and <code>/usr/bin</code> is within ${PATH}.
300
300
</details>
301
301
302
302
***
303
303
304
304
#### Modifying Environment Variables
305
305
306
-
You can modify the contents of the `$PATH` environment variable with the `export` command.
306
+
You can modify the contents of the `${PATH}` environment variable with the `export` command.
307
307
308
308
The `export` command:
309
-
* Example `export PATH=$PATH:~/opt/bin` (**do not run this**)
310
-
* The arguments or **input to `export` should always include `$PATH`**
309
+
* Example `export PATH=${PATH}:~/opt/bin` (**do not run this**)
310
+
* The arguments or **input to `export` should always include `${PATH}`**
311
311
* This specifies that you want to maintain the existing contents.
312
312
* If you don't maintain all the `bin` directories, none of your commands will work anymore!
313
313
* Use the ":" to separate added paths from one another, **with no spaces**
314
-
* The new path being added, should not end in `/`. Even though `ls ~/opt/bin` and `ls ~/opt/bin/` give you the same results, the `$PATH` variable cannot have the trailing `/`.
314
+
* The new path being added, should not end in `/`. Even though `ls ~/opt/bin` and `ls ~/opt/bin/` give you the same results, the `${PATH}` variable cannot have the trailing `/`.
315
315
* Order matters -
316
-
* If you run `export PATH=$PATH:~/opt/bin` Shell will add the `~/opt/bin` directory to **the end of the pre-existing list** within the `$PATH` environment variable.
317
-
* Alternatively, if you use `export PATH=~/opt/bin:$PATH`, the same directory will be added to the beginning of the list. The order determines which directory Shell will look in first to find a program.
316
+
* If you run `export PATH=${PATH}:~/opt/bin` Shell will add the `~/opt/bin` directory to **the end of the pre-existing list** within the `${PATH}` environment variable.
317
+
* Alternatively, if you use `export PATH=~/opt/bin:${PATH}`, the same directory will be added to the beginning of the list. The order determines which directory Shell will look in first to find a program.
318
318
319
319
This command is often used to add paths to a directory with commands you commonly want to use.
320
320
@@ -326,15 +326,15 @@ If you want to run this tool, you will have to type:
However, if `/home/rsk27/installations/alignment_tools/dna/bowtie` is part of the `$PATH` variable you can instead just type:
329
+
However, if `/home/rsk27/installations/alignment_tools/dna/bowtie` is part of the `${PATH}` variable you can instead just type:
330
330
331
331
```bash
332
332
$ bowtie2 <inputfile>
333
333
```
334
334
335
-
#### Closer look at the inner workings of the shell, in the context of $PATH
335
+
#### Closer look at the inner workings of the shell, in the context of ${PATH}
336
336
337
-
Each time you log in to a cluster, or start a new interactive session on a compute node, 2 special shell scripts are run automatically in the background. You have the ability to modify these scripts, so if you want to customize your environment you can add the customizing commands to these shell scripts. One common use of this is to add an `export` command that adds paths to the pre-existing contents of the `$PATH` environment variable.
337
+
Each time you log in to a cluster, or start a new interactive session on a compute node, 2 special shell scripts are run automatically in the background. You have the ability to modify these scripts, so if you want to customize your environment you can add the customizing commands to these shell scripts. One common use of this is to add an `export` command that adds paths to the pre-existing contents of the `${PATH}` environment variable.
338
338
339
339
So, what are these files and where are they located? These are called `.bashrc` and `.bash_profile`, and they are located in your home directory. You can create them if they don't exist, and Shell will use them!
340
340
@@ -347,7 +347,7 @@ $ ls -al ~/
347
347
348
348
> You can use `vim` to modify these files and/or create them.
349
349
350
-
**In closing, permissions and environment variables, especially `$PATH`, are very useful and important concepts to understand in the context of UNIX and HPC.**
350
+
**In closing, permissions and environment variables, especially `${PATH}`, are very useful and important concepts to understand in the context of UNIX and HPC.**
351
351
352
352
---
353
353
*This lesson has been developed by members of the teaching team at the [Harvard Chan Bioinformatics Core (HBC)](http://bioinformatics.sph.harvard.edu/). These are open access materials distributed under the terms of the [Creative Commons Attribution license](https://creativecommons.org/licenses/by/4.0/) (CC BY 4.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.*
0 commit comments