ディレクトリに必要なファイルの総数を表示するためにこのスクリプトを実行してみましたが、機能しません。
echo "please enter your directory: "
Read directory
Echo -e "Please enter your project name: "
Read projName
find $directory -type f -name ' $projName ' -exec du -ch {} + | while read file; do
echo "Reading $file"
Echo $file | grew total$
ベストアンサー1
「役に立たない」とはどういう意味ですか?
スクリプトに関連するいくつかの問題は次のとおりです。
オリジナル
#!/bin/bash
echo "Please enter directory: "
read directory
echo -e "Please enter project name: "
read projName
find $directory -type f -name ' $projName ' -exec du -ch {} + | while read file; do
echo "Reading $FILE..."
echo $FILE | grep total$
done
修正する
#! /bin/bash -
read -p "Please enter a directory: " directory # Shorter
read -p "Please enter a project name: " projName # Shorter
find "$directory" -type f -name "$projName" | while read file; do #Always double quote your variables. The single quotes around projName prevented it from being expanded.
echo "Reading $file..." # $FILE is not a valid variable in your script
du -ch "$file" # this being in an exec statement was feeding bad info to your while loop.
cat "$file" | grep 'total$' # $FILE is not a valid variable in your script. I think you want to cat the contents of the file and not echo it's filename.
done