Skip to content

Commit

Permalink
docs: add bash tip about moving to script dir
Browse files Browse the repository at this point in the history
  • Loading branch information
ansemjo committed Oct 21, 2021
1 parent a27e142 commit d7874bb
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions content/docs/tips/bash.md
Expand Up @@ -5,6 +5,14 @@ weight: 10

# bash

## Move to script directory

Sometimes you write a script that assumes that it executes from the directory that is stored in .. at least I do. Here's a handy line to put at the top of your script:

```bash
cd "$(dirname "${BASH_SOURCE[0]}")"
```

## Check if a variable is defined

The simplest approach of using `if [[ -n $var ]]; then ..` cannot detect if the
Expand Down

0 comments on commit d7874bb

Please sign in to comment.