이스케이프 문자가 포함된 확장자

이스케이프 문자가 포함된 확장자

이스케이프 문자로 인해 확장할 수 없습니다.

UNF\1122

지금은 아주 간단한 예를 들어보려고 합니다.

ps -ef | grep $USER

궁극적으로 이스케이프 문자를 처리한 후에 이 작업을 수행하고 싶습니다.

ipcs -m | grep $USER | awk '{printf "%s ",$2}'

$USER나는 그것을 하기 때문에 그것이 가치가 있다는 것을 안다 .

$ echo $USER UNF\1122

왜 관리자가 사용자 이름에 을 추가하기로 결정했는지 묻지 마십시오 \. 왜냐하면 저는 모르기 때문입니다.

이 문제를 해결하기 위해 작은따옴표와 큰따옴표를 사용해 보았습니다. 저도 이렇게 사용자 이름을 바꿔보았습니다.

USER="UNF\\\\1122" and USER='UNF\\1122'

답변1

유틸리티에 따르면 a 에서는 \1역참조와 같은 의미가 있을 수 있지만 grep에서는 의미가 없을 수 있기 때문에 까다롭습니다 getent. 쉘 보간 역시 상황을 복잡하게 만듭니다.

# getent sees a\\b, cannot find this literal string
$ getent passwd 'a\\b'

# let the shell interpolate \\ to \ so getent sees a\b
$ getent passwd a\\b
a\b:x:9999:9999:Slash Gordon:/:/bin/sh

# or no iterpolation, literal a\b passed to getent
$ getent passwd 'a\b'
a\b:x:9999:9999:Slash Gordon:/:/bin/sh

# oops, shell interpolated \\ to \ and thus grep sees \b metacharacter
$ grep "a\\b" /etc/passwd
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
a\b:x:9999:9999:Slash Gordon:/:/bin/sh

# oops, also shell interpolation, so grep sees a\b metachar
$ grep a\\b /etc/passwd
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
a\b:x:9999:9999:Slash Gordon:/:/bin/sh

# no interpolation, pass \\ to grep, which then treats as literal \
$ grep 'a\\b' /etc/passwd
a\b:x:9999:9999:Slash Gordon:/:/bin/sh
$ 

관련 정보