0

Some programs can be run like this:

$ VAR1=val1 VAR2=val2 VAR3=val3 program

I want to make a script that can be customized using these variables. For example, I have a SEPARATOR variable where I need to store a separator. Currently, I write SEPARATOR=" - " program but the variable is overwritten by the program hence nothing happens.

How do i pass that variable?

  • Show us an example program where `SEPARATOR=" - " program` doesn't work. It's _getting passed_ just fine, but you're probably doing something wrong in how you handle it inside the program -- if you set `SEPARATOR=":"` or somesuch without checking whether `SEPARATOR` was previously set that'll overwrite the passed-in value, but until we've seen inside your program we don't know what it's doing. – Charles Duffy Mar 08 '23 at 16:07
  • _Probably_, what you need is [Assigning default values to shell variables with a single command in bash](https://stackoverflow.com/questions/2013547/assigning-default-values-to-shell-variables-with-a-single-command-in-bash), but until we've seen your program that's just a guess. – Charles Duffy Mar 08 '23 at 16:09
  • (BTW, all-caps variable names is bad form: those names are reserved for variables that are meaningful to the shell itself and OS-defined tools, whereas names with at least one lowercase character are reserved for application use and guaranteed not to modify behavior of POSIX-defined tools; see https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html, fourth paragraph, keeping in mind that setting a shell variable overwrites any like-named environment variable, so the naming conventions are shared between the two classes). – Charles Duffy Mar 08 '23 at 16:10
  • (Not all of bash's parameter expansions are available in POSIX sh, but the relevant ones here are; not hearing back, I'm comfortable closing this as a duplicate until/unless you add enough information to disambiguate). – Charles Duffy Mar 08 '23 at 16:26

0 Answers0