Michael F. Stemper
2017-06-14 19:15:48 UTC
Why doesn't bash export $COLUMNS?
I wanted to add some code within a program to have its output
nicely formatted, no matter the width of the terminal in which
it was being run. Unfortunately, I wasn't able to do so, because
it didn't have access to $COLUMNS.
The following simple example shows that $COLUMNS is not exported:
***@hostname$ echo $COLUMNS
80
***@hostname$ cat > col
#!/bin/bash
echo $COLUMNS
***@hostname$ chmod +x col
***@hostname$ ./col
***@hostname$ export COLUMNS
***@hostname$ ./col
80
***@hostname$
Now that I've moved beyond denial, I'd like to understand *why*
this is so. Does anybody have a good reason why programs and
scripts shouldn't have automatic access to this particular
variable?
I wanted to add some code within a program to have its output
nicely formatted, no matter the width of the terminal in which
it was being run. Unfortunately, I wasn't able to do so, because
it didn't have access to $COLUMNS.
The following simple example shows that $COLUMNS is not exported:
***@hostname$ echo $COLUMNS
80
***@hostname$ cat > col
#!/bin/bash
echo $COLUMNS
***@hostname$ chmod +x col
***@hostname$ ./col
***@hostname$ export COLUMNS
***@hostname$ ./col
80
***@hostname$
Now that I've moved beyond denial, I'd like to understand *why*
this is so. Does anybody have a good reason why programs and
scripts shouldn't have automatic access to this particular
variable?
--
Michael F. Stemper
Life's too important to take seriously.
Michael F. Stemper
Life's too important to take seriously.