콘텐츠를 한 디렉토리에서 다른 디렉토리로 복사하는 아래 두 프로그램의 차이점은 무엇입니까?

콘텐츠를 한 디렉토리에서 다른 디렉토리로 복사하는 아래 두 프로그램의 차이점은 무엇입니까?

프로그램 번호 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쉘이 내장되어 있습니다 (참조맨페이지) 제공된 변수 이름은 다음과 같아야 합니다.~ 아니다시작하다$

관련 정보