Skip to content

Note to prefer $() over ``, and update single example to conform #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,18 @@ echo {00..8..2} # 00 02 04 06 08

## Command substitution

Command substitution allow us to evaluate a command and substitute its value into another command or variable assignment. Command substitution is performed when a command is enclosed by ``` `` ``` or `$()`. For example, we can use it as follows:
Command substitution allow us to evaluate a command and substitute its value into another command or variable assignment. Command substitution is performed when a command is enclosed by `$()` or ``` `` ```. For example, we can use it as follows:

```bash
now=`date +%T`
# or
now=$(date +%T)
# or
now=`date +%T`

echo $now # 19:08:26
```

Many prefer `$()` over ``` `` ``` because the latter cannot be nested, and the back-tick character is easy to mistake for an apostrophe in print.

## Arithmetic expansion

In bash we are free to do any arithmetical operations. But the expression must enclosed by `$(( ))` The format for arithmetic expansions is:
Expand Down Expand Up @@ -641,9 +643,9 @@ Sometimes `if..else` statements are not enough to do what we want to do. In this
Look at the example below:

```bash
if [[ `uname` == "Adam" ]]; then
if [[ $(uname) == "Adam" ]]; then
echo "Do not eat an apple!"
elif [[ `uname` == "Eva" ]]; then
elif [[ $(uname) == "Eva" ]]; then
echo "Do not take an apple!"
else
echo "Apples are delicious!"
Expand Down