Skip to content

Commit b749fd7

Browse files
authored
Updated variable to use {}
1 parent c318364 commit b749fd7

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

lessons/07_permissions_and_environment_variables.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Approximate time: 40 minutes
1010

1111
- Grant or restrict access to files on a multi-user UNIX system
1212
- 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
1414

1515
## Permissions
1616

@@ -217,28 +217,28 @@ $ env
217217

218218
It's a pretty long list! **In the context of the shell the environment variables are usually all in upper case.**
219219

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}`.
221221

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.
224224

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`:
226226

227227
```bash
228-
$ echo $HOME
228+
$ echo ${HOME}
229229
```
230230

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).
232232

233233

234234
`$HOME` is pretty straightforward, how about we take a look at what is stored in the `$PATH` variable:
235235

236236
```bash
237-
$ echo $PATH
237+
$ echo ${PATH}
238238

239239
/n/cluster/bin:/opt/singularity/bin:/usr/local/rvm/gems/ruby-2.4.9/bin:/usr/local/rvm/gems/ruby-2.4.9@global/bin:/usr/local/rvm/rubies/ruby-2.4.9/bin:/n/cluster/bin:/opt/singularity/bin:/usr/local/bin:/usr/bin:/opt/puppetlabs/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/sbin:/home/rc_training01/.local/bin:/home/rc_training01/bin
240240
```
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 ":".
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 ":".
242242

243243
Here is the list of paths in a more readable format:
244244
* `/n/cluster/bin`
@@ -261,15 +261,15 @@ Each of these paths are referring to a directory, in this case a lot of them are
261261

262262
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.
263263

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?
265265

266266
For any command you execute on the command prompt, you can find out where the executable file is located using the `which` command.
267267

268268
```bash
269269
$ which ls
270270
```
271271

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}`?
273273

274274

275275
Try it on a few of the basic commands we have learned so far:
@@ -286,35 +286,35 @@ $ ls -lF /usr/bin/
286286

287287
The path `/usr/bin` is usually where executables for commonly used commands are stored.
288288

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`**.
290290
291291
***
292292

293293
**Exercise**
294294

295-
Are the directories listed by the `which` command within `$PATH`?
295+
Are the directories listed by the `which` command within `${PATH}`?
296296

297297
<details>
298298
<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}.
300300
</details>
301301

302302
***
303303

304304
#### Modifying Environment Variables
305305

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.
307307

308308
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}`**
311311
* This specifies that you want to maintain the existing contents.
312312
* If you don't maintain all the `bin` directories, none of your commands will work anymore!
313313
* 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 `/`.
315315
* 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.
318318

319319
This command is often used to add paths to a directory with commands you commonly want to use.
320320

@@ -326,15 +326,15 @@ If you want to run this tool, you will have to type:
326326
$ /home/rsk27/installations/alignment_tools/dna/bowtie/bowtie2 <inputfile>
327327
```
328328

329-
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:
330330

331331
```bash
332332
$ bowtie2 <inputfile>
333333
```
334334

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}
336336

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.
338338

339339
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!
340340

@@ -347,7 +347,7 @@ $ ls -al ~/
347347

348348
> You can use `vim` to modify these files and/or create them.
349349
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.**
351351

352352
---
353353
*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

Comments
 (0)