あるディレクトリから別のディレクトリにコンテンツをコピーする次の2つのプログラムの違いは何ですか? [閉鎖]

あるディレクトリから別のディレクトリにコンテンツをコピーする次の2つのプログラムの違いは何ですか? [閉鎖]

プログラム番号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 

2番目のプログラム(エラーなしで実行)

#!/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シェル組み込み関数です(参照:マンページ)指定された変数名は次のとおりです。いいえ最初$

おすすめ記事