mirror of
https://github.com/samsonjs/csc360-a1-shell.git
synced 2026-04-11 11:35:47 +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
|
||||
escaped = line[i + 1]
|
||||
if escaped == "$" || escaped == "`" || escaped == "\\" || escaped == "\""
|
||||
output << (if escaped == "$"
|
||||
ESCAPED_DOLLAR
|
||||
else
|
||||
((escaped == "`") ? ESCAPED_BACKTICK : escaped)
|
||||
end)
|
||||
output << escaped_replacement(escaped)
|
||||
else
|
||||
output << "\\"
|
||||
output << escaped
|
||||
|
|
@ -272,6 +268,17 @@ module Shell
|
|||
stdout.tr("\n", " ")
|
||||
end
|
||||
|
||||
def escaped_replacement(char)
|
||||
case char
|
||||
when "$"
|
||||
ESCAPED_DOLLAR
|
||||
when "`"
|
||||
ESCAPED_BACKTICK
|
||||
else
|
||||
char
|
||||
end
|
||||
end
|
||||
|
||||
def protect_escaped_dollars(line)
|
||||
output = +""
|
||||
i = 0
|
||||
|
|
|
|||
Loading…
Reference in a new issue