[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Conditionally executing a script and using return value
From: |
Thomas Nyberg |
Subject: |
Conditionally executing a script and using return value |
Date: |
Thu, 11 Apr 2019 12:04:07 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 |
Hello,
I would like my Makefile to:
1. Check if a variable is set to specific value,
2. If it is, execute a script and get its return value,
3. Stop executing Makefile depending upon return value.
Here is the Makefile I have:
`Makefile`
-------------------------------------------------------------
FORCE=true
all: check_force
@echo "success"
check_force:
ifeq ($(FORCE),true)
$(shell sh ./prompt.sh)
endif
-------------------------------------------------------------
and here is the `prompt.sh` file:
`prompt.sh`
-------------------------------------------------------------
while true;
do
read -p "Are you sure you want force to be \"true\"? (y/n) " resp
case $resp in
[Yy]* ) echo "You picked yes"; exit 0;;
[Nn]* ) echo "You picked no"; exit 1;;
* ) echo "You picked nonsense";;
esac
done
-------------------------------------------------------------
I have tried many different variations of this with various
errors/problems, but basically I would like to stop execution if FORCE
is set to "true" and if the user selects "n" in the prompt. If the user
selects "y" I would like things to continue (in this case simply echo
"success"). If FORCE is not set to "true", I don't want the script to
execute at all.
Thanks for any help! Ask for more details if I'm not making sense...
Cheers,
Thomas
- Conditionally executing a script and using return value,
Thomas Nyberg <=