# :-

Take \${val1:-val2} for example, if val1 is unset or null, return val2, otherwise return val1.

Example:

# set -a

Definition from the Bash Manual

-a

Each variable or function that is created or modified is given the export attribute and marked for export to the environment of subsequent commands.

Honestly I haven’t fully comprehended the definition, but we can set up an example to see what it does.

1. Create foo.sh

2. Create bar.sh

3. Set executable permission

4. Source foo.sh

5. Result

As you can see, we can access all the variables defined in bar.sh in foo.sh, just as if they are marked as export. If we didn’t use set -a, the result would be

6. We can access it directly in the terminal too, they are exported all the way to the top bash environment.

# Bash Regular Expressions

We can use regular expressions with the help of =~, here is an example.

Output

Notice that you cannot use \d or \\d to replace [[:digit:]], because \d is PCRE, while it uses POSIX regex here, which doesn’t recognize \d. If you think [[:digit:]] is too long, you can use [0-9] to replace it, which has the same effect.

Output

Share