Bash .sh文件可以是makefile中的依赖项吗?
我正在Ubuntu 16.04上使用bash。我正在尝试使用makefile创建一个README.md文件,其中gussinggame.sh是依赖项。创建的README.md文件很好。但每次运行make时,即使依赖项没有更改,也会重新创建README.md文件。早些时候,我使用.txt文件作为依赖项,它们工作得很好。有人能告诉我我错过了什么吗 以下是我的密码:Bash .sh文件可以是makefile中的依赖项吗?,bash,ubuntu,makefile,Bash,Ubuntu,Makefile,我正在Ubuntu 16.04上使用bash。我正在尝试使用makefile创建一个README.md文件,其中gussinggame.sh是依赖项。创建的README.md文件很好。但每次运行make时,即使依赖项没有更改,也会重新创建README.md文件。早些时候,我使用.txt文件作为依赖项,它们工作得很好。有人能告诉我我错过了什么吗 以下是我的密码: #!/usr/bin/env bash # File: guessinggame.sh no_files_guessed=0 no_f
#!/usr/bin/env bash
# File: guessinggame.sh
no_files_guessed=0
no_files_actual=0
difference=0
# Function to prompt the user for next guess
function next_guess {
echo "Guess again:"
read no_files_guessed
}
# 1. Count the number of files in the current directory
# Excluding: Directories and Hidden files
no_files_actual=$(ls -p|grep -v '/$'|wc -l)
# 2. Ask the user to guess the number of files in the curret directory
echo "Guess the number of files in this directory and then press [ENTER]: "
# 3. Prompt the user for a guess
read no_files_guessed
# 4. Give user a clue to guess the correct no. if the initial guess is incorrect
while [[ $no_files_guessed -ne $no_files_actual ]]
do
difference=$no_files_actual-$no_files_guessed
if [[ $difference -le 10 ]] && [[ $difference -gt 0 ]]
then
echo "Your guess is low."
elif [[ $difference -ge -10 ]] && [[ $difference -lt 0 ]]
then
echo "Your guess is high."
elif [[ $difference -gt 10 ]]
then
echo "Your guess is too low."
elif [[ $difference -lt -10 ]]
then
echo "Your guess is too high."
fi
next_guess
done
# 5. Congratulate the user for guessing the correct number
if [[ $no_files_guessed -eq $no_files_actual ]]
then
echo "CONGRATULATIONS !!! Your guess is correct"
fi
生成文件:
all: README.txt
README.txt: guessinggame.sh
echo "#GUESSING GAME#" > README.md
echo >> README.md
echo "*Time Stamp at which make was run:*" >> README.md
date >> README.md
echo >> README.md
echo "Lines of code in guessinggame.sh:" >> README.md
wc -l guessinggame.sh|egrep -o '[0-9]+' >> README.md
clean:
rm README.md
它与
.sh
文件无关,这些文件可以像任何其他文件一样用作依赖项,没有什么特别之处
错误很简单:Makefile
配方声称创建了README.txt
,但实际上它创建了一个名为README.md
的文件。因此,下次运行make
时,它会看到README.txt
仍然不存在,并再次运行配方
为了防止将来出现此类错误,请使用
$@
而不是README.md
;它将扩展到目标文件的名称。这与.sh
文件无关,它可以像任何其他文件一样用作依赖项,没有什么特别的
错误很简单:Makefile
配方声称创建了README.txt
,但实际上它创建了一个名为README.md
的文件。因此,下次运行make
时,它会看到README.txt
仍然不存在,并再次运行配方
为了防止将来出现此类错误,请使用
$@
而不是README.md
;它将扩展到目标文件的名称。特别感谢@Thomas提供的$@tip。特别感谢@Thomas提供的$@tip。