Score:0

Why the variable value is not changing in the function?

ee flag

In the following function main_script, the variable DEFAULT_BACKUP_DIR is not working as intended because the value /home/user/BACKUP is not assigned to it which I do not know why, and when I try to update it in the if statement it also does not update

Note 1: This function is inside a Makefile that I use to run a Bach script file

Note 2: The variable DEFAULT_BACKUP_DIR is declared for the first time in this function and used within the scope of this function only.

define main_script
@ $(call src_dir_check,$1)
DEFAULT_BACKUP_DIR=/home/user/BACKUP
if [ -d $2 ]
then
    echo "Backup directory -$2- do exist"
    DEFAULT_BACKUP_DIR=$2
else 
    echo "ERROR! Backup directory -$2- does not exist!"
    echo "Switched to default directory -$(DEFAULT_BACKUP_DIR)-"
fi
$(call run_script,$1,$(DEFAULT_BACKUP_DIR),$3,$4)
endef

this is how I call it

.PHONY: run
run: display
    @ $(call main_script,$(SRC_DIR),$(BACKUP_DIR),$(TIME),$(MAX))

and I type the following in the terminal to run the Makefile

make run SRC_DIR=somedir BACKUP_DIR=somedir TIME=1 MAX=5

thanks in advance...

Terrance avatar
id flag
What type of script are you using this in? You tagged bash but bash doesn't use `define` at all to define any variables.
ABSO avatar
ee flag
@Terrance this function is inside a Makefile that I use to run a bash file
ar flag
Which distro and version of Linux?
ABSO avatar
ee flag
@user68186 Ubuntu-20.04.3
Terrance avatar
id flag
I have never created my own makefile, but from your code it just doesn't look quite right. I won't be much help because I am not seeing how you will be calling it. However, I do recommend that you look over the Makefile Tutorial https://makefiletutorial.com/
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.