-
Notifications
You must be signed in to change notification settings - Fork 0
/
echo_learn.sh
57 lines (50 loc) · 1.79 KB
/
echo_learn.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#----------------------------------------------------------------------------------
# The `echo` command is built into `sh` as well as `bash`. It's a simple and
# accessible way to output text to your terminal.
#
# Assuming you're using `bash`, the feature-rich `printf` giant is often the better
# choice, if portability is at all a concern, and/or when needing more oomph.
#
# Unlike most other commands, `echo` allows for unprotected strings, provided the
# characters aren't interpret-able by the shell, such as a glob (`*`).
#
# The following command should work as intended:
#
# echo this example text would display correctly
#
# However, this typically would not:
#
# echo this example * text would not display correctly
#
# It would be a good habit to quote all of your `echo` output, though.
#
# The `echo` command can make use of escape sequences*, but may require the `-e`
# flag to work. That said, on many installations of Linux, this is the default, -
# which can be set by using the `xpg_echo` shell option, set with the `shopt` bash
# builtin.
#
# * Escape sequences are, for example, `\n`, `\e[1;31m`, `\033c`, `\x3d`, etc.
#
# - written by 'terminalforlife' (AKA: 'Learn Linux')
#----------------------------------------------------------------------------------
# The following three lines have the same result.
echo "It is a test"
echo 'It is a test'
echo It is a test
# escape a character
echo "\"It is a test \""
# The above could also be written as:
echo '"It is a test "'
#print variable
name=zhiwei
echo "$name"
# new line (concatenation)
echo -e "OK! \n"
echo "It is a test"
#don't insert new line before two echo command
echo -e "OK! \c"
echo "It is a test"
# The first line has the same effect as using the `-n` flag:
echo -n "OK! "
#show command result via command substitution
echo `date`