mirror of
https://github.com/samsonjs/csc360-a1-shell.git
synced 2026-04-27 14:57:43 +00:00
Clean up command substitution escapes
This commit is contained in:
parent
d6ded9dd46
commit
a1410cb5da
1 changed files with 12 additions and 5 deletions
|
|
@ -177,11 +177,7 @@ module Shell
|
||||||
if i + 1 < line.length
|
if i + 1 < line.length
|
||||||
escaped = line[i + 1]
|
escaped = line[i + 1]
|
||||||
if escaped == "$" || escaped == "`" || escaped == "\\" || escaped == "\""
|
if escaped == "$" || escaped == "`" || escaped == "\\" || escaped == "\""
|
||||||
output << (if escaped == "$"
|
output << escaped_replacement(escaped)
|
||||||
ESCAPED_DOLLAR
|
|
||||||
else
|
|
||||||
((escaped == "`") ? ESCAPED_BACKTICK : escaped)
|
|
||||||
end)
|
|
||||||
else
|
else
|
||||||
output << "\\"
|
output << "\\"
|
||||||
output << escaped
|
output << escaped
|
||||||
|
|
@ -272,6 +268,17 @@ module Shell
|
||||||
stdout.tr("\n", " ")
|
stdout.tr("\n", " ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def escaped_replacement(char)
|
||||||
|
case char
|
||||||
|
when "$"
|
||||||
|
ESCAPED_DOLLAR
|
||||||
|
when "`"
|
||||||
|
ESCAPED_BACKTICK
|
||||||
|
else
|
||||||
|
char
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def protect_escaped_dollars(line)
|
def protect_escaped_dollars(line)
|
||||||
output = +""
|
output = +""
|
||||||
i = 0
|
i = 0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue