How do I grab a variable set via shell?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How do I grab a variable set via shell?

Lee Shallis
Here's my code snippet:

HEAD_PATH:=$(WKSDIR).git$(DIRSEP)logs$(DIRSEP)HEAD
$(info PATH=$(HEAD_PATH))
HEAD_SAFEP:=$(subst \,\\,$(HEAD_PATH))
$(info SAFEP=$(HEAD_SAFEP))
HEAD_COUNT_STR:=$(shell find /c " +" $(HEAD_PATH))
VARBEG:=%
VAREND:=%
$(info COUNT_STR=$(HEAD_COUNT_STR))
# % ignores case so we don't need to go out of our way to convert our path to
# uppercase however it only works in patsubst which ignores the ----------
# before the path so we get subst to remove the left over leaving the number we
# wanted
sh_let:=set /a
HEAD_COUNT:=$(subst ---------- ,,$(patsubst %:,,$(HEAD_COUNT_STR)))
$(info COUNT=$(HEAD_COUNT))
HEAD_NMONE_STR:=$(shell $(sh_let) math_result=$(HEAD_COUNT)-1)
HEAD_NMONE:=$(shell echo $(math_result))

$(info NMONE=$(HEAD_NMONE))
HEAD_LASTL:=$(shell more +$(HEAD_NMONE) $(HEAD_PATH))
$(info LASTL=$(HEAD_LASTL))

I also highlighted the key snippet, I eventually figured out how to perform arithmetic without extra programs being installed but I still have the issue of grabbing the result to confirm it worked correctly, does anyone have experience of this sort of thing?

------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: How do I grab a variable set via shell?

Lee Shallis
Never mind I figured it out:

# Running this on windows as well so I've set the shell commands to be windows equivalent
SHELL:=cmd.exe
sh_let:=set /a
sh_addcmd:=&
sh_getlet:=set
HEAD_PATH:=$(WKSDIR).git$(DIRSEP)logs$(DIRSEP)HEAD
$(info PATH=$(HEAD_PATH))
HEAD_SAFEP:=$(subst \,\\,$(HEAD_PATH))
$(info SAFEP=$(HEAD_SAFEP))
HEAD_COUNT_STR:=$(shell find /c " +" $(HEAD_PATH))
$(info COUNT_STR=$(HEAD_COUNT_STR))
# % ignores case so we don't need to go out of our way to convert our path to
# uppercase however it only works in patsubst which ignores the ----------
# before the path so we get subst to remove the left over leaving the number we
# wanted
HEAD_COUNT:=$(subst ---------- ,,$(patsubst %:,,$(HEAD_COUNT_STR)))
$(info COUNT=$(HEAD_COUNT))
#export math_result=$(HEAD_COUNT)
HEAD_SHELL_STR:=$(sh_let)math_result="${HEAD_COUNT} - 1" $(sh_addcmd) $(sh_getlet) math_result
$(info SHELL_STR=$(HEAD_SHELL_STR))
HEAD_NMONE:=$(subst math_result=,,$(substĀ  ,,$(shell $(HEAD_SHELL_STR))))
$(info NMONE=$(HEAD_NMONE))
HEAD_LASTL:=$(shell more +$(HEAD_NMONE) $(HEAD_PATH))
$(info LASTL=$(HEAD_LASTL))

Incidentally I seem to have forgotten to mention that this is being used in a makefile as I also forgot that I was sending this into a more general mailing list.

On 11 May 2016 at 09:44, Lee Shallis <[hidden email]> wrote:
Here's my code snippet:

HEAD_PATH:=$(WKSDIR).git$(DIRSEP)logs$(DIRSEP)HEAD
$(info PATH=$(HEAD_PATH))
HEAD_SAFEP:=$(subst \,\\,$(HEAD_PATH))
$(info SAFEP=$(HEAD_SAFEP))
HEAD_COUNT_STR:=$(shell find /c " +" $(HEAD_PATH))
VARBEG:=%
VAREND:=%
$(info COUNT_STR=$(HEAD_COUNT_STR))
# % ignores case so we don't need to go out of our way to convert our path to
# uppercase however it only works in patsubst which ignores the ----------
# before the path so we get subst to remove the left over leaving the number we
# wanted
sh_let:=set /a
HEAD_COUNT:=$(subst ---------- ,,$(patsubst %:,,$(HEAD_COUNT_STR)))
$(info COUNT=$(HEAD_COUNT))
HEAD_NMONE_STR:=$(shell $(sh_let) math_result=$(HEAD_COUNT)-1)
HEAD_NMONE:=$(shell echo $(math_result))

$(info NMONE=$(HEAD_NMONE))
HEAD_LASTL:=$(shell more +$(HEAD_NMONE) $(HEAD_PATH))
$(info LASTL=$(HEAD_LASTL))

I also highlighted the key snippet, I eventually figured out how to perform arithmetic without extra programs being installed but I still have the issue of grabbing the result to confirm it worked correctly, does anyone have experience of this sort of thing?


------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe