[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Can the exit status of the code block in @(...) be obtained from out
From: |
Hongyi Zhao |
Subject: |
Re: Can the exit status of the code block in @(...) be obtained from outside the @() structure? |
Date: |
Sat, 22 Jan 2022 10:50:38 +0800 |
On Sat, Jan 22, 2022 at 9:40 AM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> On Sat, Jan 22, 2022 at 9:28 AM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
> >
> > On Sat, Jan 22, 2022 at 3:05 AM Paul Smith <psmith@gnu.org> wrote:
> > > [...]
> > > As mentioned before, the entire script must be contained in a single
> > > logical line if you want the same shell to interpret it all. So you'll
> > > have to add "\" to combine all these into a single logical line:
> >
> > Thank you for your above knowledgeable and thorough analysis. Got it.
> >
> > > define download_and_unpack
> > > package='$(1)' ; \
> > > package_URL='$(2)' ; \
> > > package_directory='$(3)' ; \
> > > package_code='$(4)' ; \
> > > package_archive=../archive/`echo "$(package)" | sed
> > > 's/.*\///;s/.*=//'` ; \
> > > ( \
> > > if ! gzip -t $(package_archive) > /dev/null 2>&1 ; then \
> >
> > I tried with your above trick, but noticed that the variable
> > package_archive can be expanded correctly:
> >
> > $ make -j44 w90
> > [...]
> > package='wannier90-3.1.0';
> > package_URL='https://codeload.github.com/wannier-developers/wannier90/tar.gz/v3.1.0';
> > package_directory='W90'; package_code='wannier90';
> > package_archive=../archive/`echo "" | sed 's/.*\///;s/.*=//'`;
> >
> > As you can see, the following command:
> >
> > package_archive=../archive/`echo "$(package)" | sed 's/.*\///;s/.*=//'`; \
> >
> > will be passed as:
> >
> > package_archive=../archive/`echo "" | sed 's/.*\///;s/.*=//'`;
> >
> > As you can see, the expansion of "$(package)" has been lost. Based on
> > tries, it seems the following form fixes this problem:
> >
> > package_archive=../archive/`echo "$$(package)" | sed 's/.*\///;s/.*=//'`; \
>
> Sorry, it should be written as follows:
>
> package_archive=../archive/`echo "$${package}" | sed 's/.*\///;s/.*=//'`; \
>
> And then refer to these variables using the following formats:
>
> $${package}
> $${package_URL}
> $${package_directory}
> $${package_code}
> $${package_archive}
>
> The above conclusion comes from the following script snippet:
The final version using the above ideas and techniques is as follows:
=== begin ===
define download_and_unpack
package='$(1)'; \
package_URL='$(2)'; \
package_directory='$(3)'; \
package_code='$(4)'; \
package_archive=../archive/`echo "$${package}" | sed 's/.*\///;s/.*=//'`; \
(if ! gzip -t $${package_archive} > /dev/null 2>&1; then \
rm -fr $${package_archive} ; \
wget -O $${package_archive} $${package_URL} > /dev/null 2>&1; \
if [ $$? -ne 0 ]; then \
curl -o $${package_archive} $${package_URL} > /dev/null 2>&1; \
if [ $$? -ne 0 ]; then \
echo "*** Unable to download $${package_code}. Test whether
curl or wget is installed and working," ; \
echo "*** if you have direct access to internet. If not,
copy into archive/ the file" ; \
echo "*** located here $${package_URL}" ; \
exit 1 ; \
fi; \
fi; \
fi \
); \
if [ $$? -eq 0 -a ! -e ../$${package_directory} ]; then \
(gzip -dc $${package_archive} | \
(cd ../ ; tar -xvf - )) ; \
if [ $$? -ne 0 ]; then \
echo "*** Unable to download $${package_URL}." ; \
echo "*** Verify that the url is correct." ; \
exit 1 ; \
else \
(cd ../ ; ln -s $${package} $${package_directory}); \
fi; \
fi
endef
=== end ===
Regards,
HZ
- Re: Can the exit status of the code block in @(...) be obtained from outside the @() structure?, (continued)
Re: Can the exit status of the code block in @(...) be obtained from outside the @() structure?, Hongyi Zhao, 2022/01/20
Re: Can the exit status of the code block in @(...) be obtained from outside the @() structure?, Paul Smith, 2022/01/21
Re: Can the exit status of the code block in @(...) be obtained from outside the @() structure?, Hongyi Zhao, 2022/01/21
Re: Can the exit status of the code block in @(...) be obtained from outside the @() structure?, Hongyi Zhao, 2022/01/21
Re: Can the exit status of the code block in @(...) be obtained from outside the @() structure?, Hongyi Zhao, 2022/01/21
Re: Can the exit status of the code block in @(...) be obtained from outside the @() structure?,
Hongyi Zhao <=
Re: Can the exit status of the code block in @(...) be obtained from outside the @() structure?, Hongyi Zhao, 2022/01/21
Re: Can the exit status of the code block in @(...) be obtained from outside the @() structure?, Hongyi Zhao, 2022/01/21