2013-04-10 1 views
0

Symfony 2 프로젝트를 구성하는 동안 cachelog 디렉토리에 적절한 권한을 설정해야합니다.bash 명령에 지정된 수정자가 있는지 확인하십시오.

문서는 두 가지 방법으로 수행 할 것이라고 말합니다. 그들 중 하나는 -m 수정 자로 setfacl 명령을 호출합니다. 그러나 모든 버전이이 수정자를 포함하지는 않습니다. 이 명령이나 다른 명령으로 수정자를 설정할 수 있는지 확인할 수 있습니까? 다음 의사와 예를 들어

:

if [ checkmods --command=setfacl --modificator=-m ] 
    setfacl -m .... 
else 
    chmod ... 
+1

http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=blob;f=bash_completion

그냥 생각?은'$를 확인하는'정의되지 않은 modificator으로 실행될 때 대부분의 명령은'1'을 반환하기 때문에 '0'상태. 다른 사람들은 단지 그들을 무시하지만 ... – tamasgal

+0

modifator를 가진 정규 호출 명령은 파일 시스템에 영향을 줄 수 있습니다. 일부 샌드 박스 호출을 찾고 있습니다. – hsz

+0

명령에'--help' 출력이 있습니까? 아마 수정자를 "grepping";) – tamasgal

답변

1

당신은 setfacl --help을 실행하여 사용 정보를 구문 분석하고 modificator이 포함 된 경우 확인할 수 있습니다. 예를 들면 : 당신이 --help 옵션이있는 명령을 수행 할 경우

if setfacl --help | grep -q -- -m, 
then 
    echo "setfacl -m supported" 
else 
    echo "setfacl -m not supported" 
fi 

, 당신의 bash는 완성 파일에서 사용할 수있는 _parse_help 기능을 살펴.

# Parse GNU style help output of the given command. 
# @param $1 command; if "-", read from stdin and ignore rest of args 
# @param $2 command options (default: --help) 
# 
_parse_help() 
{ 
    eval local cmd=$(quote "$1") 
    local line 
    { case $cmd in 
     -) cat ;; 
     *) LC_ALL=C "$(dequote "$cmd")" ${2:---help} 2>&1 ;; 
     esac } \ 
    | while read -r line; do 

     [[ $line == *([ $'\t'])-* ]] || continue 
     # transform "-f FOO, --foo=FOO" to "-f , --foo=FOO" etc 
     while [[ $line =~ \ 
      ((^|[^-])-[A-Za-z0-9?][[:space:]]+)\[?[A-Z0-9]+\]? ]]; do 
      line=${line/"${BASH_REMATCH[0]}"/"${BASH_REMATCH[1]}"} 
     done 
     __parse_options "${line// or /, }" 

    done 
} 
관련 문제