![한 디렉터리에서 다른 디렉터리로 콘텐츠를 복사하는 다음 두 프로그램의 차이점은 무엇입니까? [폐쇄]](https://linux55.com/image/168906/%ED%95%9C%20%EB%94%94%EB%A0%89%ED%84%B0%EB%A6%AC%EC%97%90%EC%84%9C%20%EB%8B%A4%EB%A5%B8%20%EB%94%94%EB%A0%89%ED%84%B0%EB%A6%AC%EB%A1%9C%20%EC%BD%98%ED%85%90%EC%B8%A0%EB%A5%BC%20%EB%B3%B5%EC%82%AC%ED%95%98%EB%8A%94%20%EB%8B%A4%EC%9D%8C%20%EB%91%90%20%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%A8%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%ED%8F%90%EC%87%84%5D.png)
프로그램 번호 1(오류 발생)
#!/bin/bash
echo "Enter source and destination directories: "
read $src $dest
if [ -d $src ] && [ -d $dest ]
then
echo "Process will start "
else
echo "Enter valid directories"
exit 1
fi
cp -r $src $dest
status=$?
if [ $? -eq 0 ]
then
echo "Successfully completed "
else
echo "facing some problems "
fi
두 번째 프로그램(오류 없이 실행됨)
#!/bin/bash
echo "Enter Sourse Directory name : "
read src
echo "Enter destination directory: "
read dest
if [ ! -d $src ]
then
echo "Enter Valid Directory name "
exit 1
elif [ ! -d $dest ]
then
echo "Enter Valid Destination source name "
exit 2
fi
cp -r $src $dest
status=$?
if [ $status -eq 0 ]
then
echo "File copied succesfully"
else
echo "there is a problem"
fi
답변1
엄청난 차이가 바로 눈앞에 있습니다.
옵션 1:
read $src $dest
시나리오 2:
read src
[...]
read dst
read
쉘 내장 함수입니다(참조:맨페이지) 제공된 변수 이름은 다음과 같아야 합니다.아니요첫 번째$