POSIX Shell: escaping strings in backquote command entries

I am writing a shell, and the POSIX shell spec is a little confused . Say I have a command:

echo "`echo "a\\
b"`"

If the output of the shell

ab

or

a\
b

?

In other words, are line continuations repeated after removing escaping from text in command substitution? The POSIX specification states that the deletion of the line continuation will not be repeated, however, all the shells under test (bash, dash, and the boot box) start the deletion of the line continuation again, as a result of which the test script outputs ab.

Script explanation:

The part of the script that is not reset inside command substitution creates:

echo "a\
b"

, , , echo "ab" , a b.

+4
1
  • `...` \ escape-, .

    \ , , : $, ` \.

    • : \$, \` \\ escape-, .

    • , \\<newline> \<newline>, `...` \\ , \

    • , .

    • \<newline> ( ), .

    • ab, , echo.

    • bash , : set -xv

  • $(...) , .

    - , .

    • $(...) ( bash, dash, ksh zsh):

      echo "$(echo "a\\
      b")"
      
      # Output
      a\
      b         
      
    • $(...) , bash, dash, ksh zsh, `...`, ksh (. ).


POSIX- - bash, dash, ksh, zsh

  • ksh ( 93u+) , ksh ". `...`, \" - .
    $(...) .

  • bash, dash zsh `...`, ( bash, , POSIX ).

    • , \" - `...`, ksh.
    • , - , , " , escape-, \ `...`; , echo "`echo \"a b\"`" "a b", a b.

: -

POSIX- , shall, CLI REPL POSIX- .

bash, dash, ksh zsh ( , ).

script ./tst, , shall :

shall ./tst

- :

<code> should </code> sample output

, ksh , ksh " `...`, \".
, $(...) .

shall npm registry (Linux macOS)

. Node.js, npm, ;
curl -L https://git.io/n-install | bash

Node.js, :

[sudo] npm install shall -g

  • sudo, , Node.js ; EACCES, sudo.
  • -g shall $PATH.

( Unix bash)

  • bash script shall.
  • chmod +x shall.
  • $PATH, /usr/local/bin (macOS) /usr/bin (Linux).
+2

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


All Articles