LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-16-2019, 08:30 PM   #1
Coalescence
LQ Newbie
 
Registered: Sep 2019
Posts: 2

Rep: Reputation: Disabled
How do you create a script that creates a new local variable?


Name: ANY
Value: Value

I've worked on this for hours, please help c;
 
Old 09-16-2019, 08:39 PM   #2
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Local?

Code:
foo () {
Name=ANY
Value=Value
}

echo $Name $Value
foo
echo $Name $Value
 
Old 09-16-2019, 08:44 PM   #3
Coalescence
LQ Newbie
 
Registered: Sep 2019
Posts: 2

Original Poster
Rep: Reputation: Disabled
How do I convert that into bash? I need it to be one line
 
Old 09-16-2019, 08:55 PM   #4
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
it is bash

and what do you mean by local?

if you run a bash script, and have it set vars. they will only live as long as that bash session , when the script exits the vars are 'lost'

I did a bash function, it lives in current session, so if it sets vars, they remain

Code:
foo () {
Name=ANY
Value=Value
}
put that in a file, lets call it func_foo.bash
and source it ( with a . )
Code:
. /path/to/func_foo.bash

echo $Name $Value
foo
echo $Name $Value

one line?
Code:
foo () { Name="ANY" ; Value="Value" }
 
Old 09-17-2019, 02:01 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
I do not really understand what do you need.
Quote:
Originally Posted by Coalescence View Post
I've worked on this for hours
Can you explain what did you try? What's happened?
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help creating bash script that creates directories based on what you answer Profound_Darkness Linux - General 10 03-26-2013 10:34 AM
how to create a bash script that creates a bar graph in the terminal window Satsugyo Linux - Newbie 10 11-26-2012 01:37 AM
AWK a variable Ouptut to a new variable and using the new variable with the old one alertroshannow Linux - Newbie 4 02-16-2009 12:08 AM
how to set a variable in a script and have the variable still set after script termin john test Linux - Newbie 9 10-21-2008 05:21 PM
LXer: Piracy creates jobs, FOSS creates opportunities LXer Syndicated Linux News 0 11-02-2006 11:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration