점이 존재한다.함수에서 찾을 수 없습니다 기본적인 bash 명령을 호출할 때 다른 기능
문제
나는 다음과 같은 bash 스크립트(이것은 단순화된 버전의 더 복잡한는 스크립트).
#!/usr/bin/env bash
set -x
function execute() {
`$1` # same as $($1), gives "command not found" as do all the following:
# $1 # or ${1}
# eval "$1"
# eval $1
# This gives "No such file or directory" even though it *is* there...
#"$1"
}
function runCommand() {
PATH="${1}"
execute "chmod 777 ${PATH}"
}
execute "chmod 777 ${1}"
runCommand "$1"
#EOF
난 그것을 실행할 때 나는 다음과 같은 출력:
+ execute 'chmod 777 build.test-case.sh'
++ chmod 777 build.test-case.sh
+ runCommand build.test-case.sh
+ PATH=build.test-case.sh
+ execute 'chmod 777 build.test-case.sh'
++ chmod 777 build.test-case.sh
./build.test-case.sh: line 5: chmod: command not found
그래서 chmod
작동할 때 execute
함수가 호출에 직접 하지만 실패하면에서 호출의 다른 기능도 있지만 디버깅 출력을 것 같다 정확히 동일한...
할 수 있는 사람이 이것을 설명한 행동은?
해결책
문제를 덮어쓰기 경로 변수를 포함하는 경로는 디렉터리 바이너리,아 chmod
중 하나,그래서 그 이유는 그것을 찾을 수 없습니다.
당신이 사용하는 경우 다른 변수,대 PATH
을 위해,당신의 runCommand()
기능,그것은 작동은 다음과 같습니다.
function runCommand() {
VAR="${1}"
execute "chmod 777 ${VAR}"
}
제휴하지 않습니다 StackOverflow