The difference of $I $() ${} in shell

Time:2020-1-22

The wonderful writing method in shell is not only (.), {.}, (.) and so on, but also all kinds of strange writing methods and details that need attention. If you don’t pay attention, you will find that the result is not the same as expected

Let’s first demonstrate a basic

a = "b"
echo $a

The result is nothing printed. The correct way to write it is=There is no space on either sidea="b"

After realizing the wonderful writing methods in shell, we need to have a basic understanding of various writing methods

  1. Without parentheses, it is a normal value taking method, but it is not easy to use in quotation marks.
  2. Single quotation marks. Output as is, but still parse & dollar; {var}
  3. Double quotation marks. Will parse & dollar; {var}, & dollar; VaR, and Command & dollar; (expr)
  4. ${}。 Value operation
  5. Back quotes. Execute as an order
  6. $()。 The bracketed content is executed as a command

Then let’s take a look at the use of these writing methods

i=i

#Normal value, 1
echo $i

#Output as is, $I
echo '$i'

#Normal value, 1
echo "$i"

#Normal value, 1
echo ${i}

#Execute as command
echo `date -d "1 days ago" +"%Y-%m-%d"`

#Execute as command
echo $(date -d "1 days ago" +"%Y-%m-%d")

If you have a single quotation mark and a double quotation mark, you can’t use & dollar; DS here. You can only use & dollar; {DS}

echo "insert overwrite table table_name partition (ds='${ds}') select distinct name from table_name_pre where ds='${ds}';"



Welcome to subscribe to “k-tertiary blockchain” – focus on blockchain technology learning
The difference of $I $() ${} in shell
Blog address: http://www.jouypub.com
Jianshu homepage: https://www.jianshu.com/u/756c9c8ae984
Segmentfault homepage: https://segmentfault.com/blog/jouypub
Tencent cloud homepage: https://cloud.tencent.com/developer/column/72548

Recommended Today

RCAST 35: add type to currency

– font ALT: Simsun; MSO font charset: 134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} @font-face {font-family:”Cambria Math”; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:1; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} @font-face {font-family:Calibri; Variable; Ose-1: 216301111; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} /\* Style […]