
나는 이 명령을 가지고 있습니다(자세한 내용은Google이 선택한 텍스트 바로가기):
sh -c 'firefox -remote "openURL(http://www.google.com/search?q=$(xsel),new-tab)"'
그러나 그것으로 끝나는 텍스트를 선택하면 )
닫는 괄호로 구문 분석됩니다.
해결책이 있나요? (어떻게든 탈출하는 것처럼요?)
답변1
반환된 문자열을 URL 인코딩해야 합니다 xsel
. 파이썬 사용:
sh -c 'firefox -remote "openURL(http://www.google.com/search?q=$(python -c "import urllib, sys; print urllib.quote(sys.argv[1])" "$(xsel)"),new-tab)"'
sh -c 'firefox -remote "openURL(http://www.google.com/search?q=$(perl -MURI::Escape -e '\''print uri_escape($ARGV[0]);'\'' "$(xsel)"),new-tab)"'
설명하다
Google 검색 수행을 요청하면 firefox
어떤 일이 발생하는지 확인하세요 foo()
.
$ firefox -remote 'openURL(http://www.google.com/search?q=Foo(),new-tab)'
Error: Failed to send command: 500 command not parseable
"파싱 가능"하게 만들려면 문자를 URL 인코딩해야 합니다. 예를 들어 Foo()
인코딩 후에는 다음과 같습니다.
$ python -c "import urllib, sys; print urllib.quote(sys.argv[1])" "Foo()"
Foo%28%29