Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Help /proggles/~

Name: Anonymous 2012-08-03 2:06

I'm currently working on a bash script and I want to define multiple variables the same way. All of them are defined the same, so it seems inefficient to define each one individually. Is there a way to define an entire array all at once, rather than each individual variable?

This is an extreme oversimplification, but I want to do something like this:

array=( $a $b $c)
array=1

And then all the variables would have a value of 1.

Here's something like what I'm currently doing:
a=1
b=1
c=1

It seems like such an inefficient way to do it though. So what should I do?

Thanks in advance for any and all help.

Name: Anonymous 2012-08-03 2:12

Actually, I found another solution, but it still involves multiple lines:

function asdf() {
[insert function for defining the variables here]
}
a=$(asdf)
b=$(asdf)
c=$(asdf)


It's an improvement, but it's still not ideal. Any thoughts on any other way to do it? Or should I not dwell on stuff like this?

Name: Anonymous 2012-08-03 3:09

>>2

What do the variables represent and where are they used? Would it be possible to name them all the same and replace all references to usage of a single variable? If they are never modified this will be possible. But if they are modified, it is a different story. I wouldn't worry about the redundancy if it is the second case.

Name: Anonymous 2012-08-03 3:36

>>3
They will be modified. I guess I'll just use a function like in >>2

Name: Anonymous 2012-08-03 12:35

fuck bash.theres no reason these days to use that shit. bash should be declared Read Only.

Don't change these.
Name: Email:
Entire Thread Thread List