2013-07-14 2 views
2

나는 이것을 여러 번했는데, 제대로 작동하지 않는 것 같습니다. 왜 그 이유를 설명 할 수 있습니까? 이 을 가정 무엇

function Foobar 
{ 
    cmd -opt1 -opt2 [email protected] 
} 

Foobar를 호출하면 cmd를 호출하는 것과 같은 일을하도록 그것을 만들 것입니다,하지만 몇 가지 추가 매개 변수 (이 예에서는 -opt1-opt2)와.

불행히도, 이것은 제대로 작동하지 않습니다. 모든 인수에 공백이 없으면 제대로 작동합니다. 그러나 공백이있는 인수를 원하면 따옴표로, Bash는 따옴표를 제거하여 명령을 분리합니다. 이 잘못된 동작을 방지하려면 어떻게합니까? bash는 맨의 특수 매개 변수 섹션에서

function Foobar 
{ 
    cmd -opt1 -opt2 "[email protected]" 
} 

편집 :

+0

@'$의 @는'사용자 정의 변수 이름이 아닙니다 때문이 아닌 관련이 isaach1000 -이 현재 스크립트 또는 함수에 인수 목록을 액세스하는 데 사용되는 POSIX 지정 이름입니다. –

답변

8

당신은 인수 값을 대체 한 후 원하지 않는 구문 분석 단계 (단어 분리 등을) 수행하는 떠들썩한 파티를 유지하기 위해 [email protected]을 두 번 인용을 수행해야합니다

@ Expands to the positional parameters, starting from one. When 
    the expansion occurs within double quotes, each parameter 
    expands to a separate word. That is, "[email protected]" is equivalent to "$1" 
    "$2" ... If the double-quoted expansion occurs within a word, 
    the expansion of the first parameter is joined with the begin- 
    ning part of the original word, and the expansion of the last 
    parameter is joined with the last part of the original word. 
    When there are no positional parameters, "[email protected]" and [email protected] expand to 
    nothing (i.e., they are removed). 
+0

그냥'$ @'을 확장하지 않고 모든 내용을 하나의 단어로 취급합니까? – MathematicalOrchid

+1

아니요,'$ @'는 그 점에서 특별히 다루어집니다. –

+0

... 확인 ... 임의의 특수 케이스 규칙 FTW! : -/ – MathematicalOrchid