![filename=${1:-/etc/hosts}와 filename=/etc/hosts의 차이점은 무엇입니까? [복사]](https://linux55.com/image/39000/filename%3D%24%7B1%3A-%2Fetc%2Fhosts%7D%EC%99%80%20filename%3D%2Fetc%2Fhosts%EC%9D%98%20%EC%B0%A8%EC%9D%B4%EC%A0%90%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F%20%5B%EB%B3%B5%EC%82%AC%5D.png)
filename=${1:-/etc/hosts}
이들그리고 그리고 의 차이점은 무엇인가요 filename=/etc/hosts
?
예를 들어:
filename=/etc/hosts
if [ -r "$filename" ] && [ -s "$filename" ]; then
md5sum $filename
else
echo "$filename cannot be processed"
fi
그리고
filename=${1:-/etc/hosts}
if [ -r "$filename" ] && [ -s "$filename" ]; then
md5sum $filename
else
echo "$filename cannot be processed"
fi
답변1
filename=${1:-/etc/hosts}
설정되지 않거나 null인 경우 /etc/hosts
변수에 값이 할당됩니다.filename
$1
~에서GNU 배쉬 매뉴얼:
${parameter:-word}
설정 되지
parameter
않거나 비어 있으면 단어의 확장이 대체됩니다. 그렇지 않으면parameter
값이 대체됩니다.