Bash parsing and shell extension

I am confused about how bash parses input and performs extension.

For input say, \'"\"hello world\""is passed as an argument to bash in a script that displays what it is inputting, I'm not quite sure how bash parses it.

Example

var=\'"\"hello   world\""
./displaywhatiget.sh "$var"
I got '"hello   world"

I understand that double quotes in "$var"tell bash to consider the value vartogether. However, I do not understand when the backslash and double quotes for a value fail during the bash extension process.

I come from shell-operation and shell extension .

+4
source share
2 answers

, var=\'"\"hello world\"". :

  • \' - . , . , '.
  • " - .
  • \" - ; , , " .
  • hello world - , . : , .
  • \" - ; , , ".
  • " - .

, var '"hello world". ./displaywhatiget.sh "$var" , $var var, ; script.

UPDATE: set -vx, bash . , , , , ( ), , , , ( , ). , , - var=''\''"hello world"'. :

  • '' - ; . , bash . , , . BTW, , : .
  • \' - , . '.
  • ' - . , .
  • "hello world" - , , .
  • ' - .

, var, . :

var=\''"hello world"'
var="'\"hello world\""
var=\'\"hello\ world\"
var="'"'"hello world"'
var=$'\'"hello world"'

... . bash set -vx.

+5

\ - :

var=\'"\"hello   world\""

Bash $var: '"hello world".

$var ("$var") - $var .

, () ( quote ).

+1

Source: https://habr.com/ru/post/1666806/


All Articles