On Sat, Jan 22, 2022 at 9:40 AM Hongyi Zhao <hongyi.z...@gmail.com> wrote: > > On Sat, Jan 22, 2022 at 9:28 AM Hongyi Zhao <hongyi.z...@gmail.com> wrote: > > > > On Sat, Jan 22, 2022 at 3:05 AM Paul Smith <psm...@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}
Even so, it seems still rather ugly and cumbersome. As suggested by Sam Kendall <sckenda...@gmail.com>, I really want to work out a pure shell script based solution as the drop-in replacement. Regards, HZ