WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: [Solved] variable expansion inside a here-file issue  (Read 4118 times)

Offline patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 715
Re: [Solved] variable expansion inside a here-file issue
« Reply #15 on: July 17, 2023, 05:00:37 AM »
I can't get this of my head, just remembers that linux use two variables settings.
First you have the shell variables, which is not transferred between parent to child.
And you have something called environment variables. that stays between parent to child.

So if you want the variable to stay between parent to child you need to export it.

If i don't misunderstand your problem it seems to maybe be that the shell spawn's another shell and don't inherit the variable between parent to child.

So maybe when you assign your variable within your shell, just add the command export in front of it like this:
Code: (bash) [Select]
export N="Test"

Code: (bash) [Select]
not like this:
N="Test"

Lets play with this like this.
Code: (bash) [Select]
> TEST="Test"
> echo $TEST
Test
> bash
> echo $TEST

> exit
exit
> echo $TEST
Test
> export TEST
> bash
> echo $TEST
Test
> exit
exit
> export TEST1="Test2"
> bash
> echo $TEST1
Test2
> exit
exit


Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: [Solved] variable expansion inside a here-file issue
« Reply #16 on: July 17, 2023, 07:52:33 AM »
Hi patrikg,

You are quite right about exported variables. But if we are discussing the issue that broke aus9's script it crawls from another grim door named "here-files" or maybe "here-documents". Are You acquainted with this topic?

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1513
Re: [Solved] variable expansion inside a here-file issue
« Reply #17 on: July 17, 2023, 10:21:37 AM »
the issue that broke aus9's script...crawls from another grim door...
Hi, Andrey. Thanks for making me laugh ;D

What I like best about GNU/Linux is that there are no "Keep Out" signs anywhere. Other OSes seem not to have grim doors and crawling things--but that's only because the user is not allowed to look around.
« Last Edit: July 17, 2023, 10:25:15 AM by GNUser »

Offline patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 715
Re: [Solved] variable expansion inside a here-file issue
« Reply #18 on: July 17, 2023, 10:36:00 AM »
Hi patrikg,

You are quite right about exported variables. But if we are discussing the issue that broke aus9's script it crawls from another grim door named "here-files" or maybe "here-documents". Are You acquainted with this topic?

Yes I am familer with this type of word and there meaning.
Okey I get it, I think.
Like the good movie Inception, nested/recursion things like dream in a dream, and what that is being supported with heredoc or herefile.
« Last Edit: July 17, 2023, 10:38:05 AM by patrikg »

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1513
Re: [Solved] variable expansion inside a here-file issue
« Reply #19 on: July 17, 2023, 11:07:37 AM »
I would try 1000 other approaches before considering a nested here document. I don't like pain.

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: [Solved] variable expansion inside a here-file issue
« Reply #20 on: July 17, 2023, 11:07:50 AM »
Hi, Andrey. Thanks for making me laugh ;D

What I like best about GNU/Linux is that there are no "Keep Out" signs anywhere. Other OSes seem not to have grim doors and crawling things--but that's only because the user is not allowed to look around.

Hi Bruno,

I like You validate my jokes about shell ) But, seriously, I'm scared with it ( It doesn't play fairly. Still probably this is my personal attitude, I wrote a lot in various assemblers so You can believe me I am quite comfortable without any doors and even walls at all ) Nice that You keep calm and happy using shell! Hope we will appeal to You as the last resort when the next time shell will put the gun to the head of the next innocent programmer threatening to push the trigger. Damn, I am frightening myself. Time to stop )

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: [Solved] variable expansion inside a here-file issue
« Reply #21 on: July 17, 2023, 11:09:04 AM »
I would try 1000 other approaches before considering a nested here document. I don't like pain.

Well, this is said by man who enjoy shell! Worth believing.

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: [Solved] variable expansion inside a here-file issue
« Reply #22 on: July 17, 2023, 11:16:02 AM »
Yes I am familer with this type of word and there meaning.
Okey I get it, I think.

The trouble occurs because inside the here-file fragment assignments are not performed, while variables expansion takes place. Inside the here-file the text is simply text, not the source. Try to examine aus9's script from this point of view.