Sign in to follow this  
Followers 0
neuro

interesting conundrum

8 posts in this topic

I assume that this might work with other variables, but this is an example. I'm on Slack 9.1 kernel 2.6.2.

bash-2.05b$ echo $COLUMNS80bash-2.05b$

when ran strait from the console, the number of columns is printed.

but in a teeny bash script:

#!/bin/bashecho $COLUMNS

it doesn't do anything:

bash-2.05b$ chmod +x ./columns.sh bash-2.05b$ ./columns.sh bash-2.05b$ 

why?

0

Share this post


Link to post
Share on other sites

without knowing too much about bash scripting, i assume it has to do with the scope of the variables. forexample a script may by default only use local vars, where you want to find the value of a global var. in any case, it would seem to be a problem with the scope of the var.

0

Share this post


Link to post
Share on other sites

alright, nevermind

i did some looking into it. and $COLUMNS and $LINES show up as blank from a bash script on my slack box too. all the other system vars seem ok. so i know not what your problem is.

0

Share this post


Link to post
Share on other sites

I mean, it's apparent that scripts run in a differnt "place", or something, but I'd really just like to understand how this works.

0

Share this post


Link to post
Share on other sites

each script runs in it's own space, but it has it's own "environment" which is populated with bash specific special vars. so there are a bunch of vars that work, like $BASH and $HOSTNAME. $COLUMNS and $LINES just shows up as blank, it could be because these are numbers values, all the other special vars i've tried are strings and print out just fine. i don't know what to do about that though

0

Share this post


Link to post
Share on other sites
each script runs in it's own space, but it has it's own "environment" which is populated with bash specific special vars. so there are a bunch of vars that work, like $BASH and $HOSTNAME. $COLUMNS and $LINES just shows up as blank, it could be because these are numbers values, all the other special vars i've tried are strings and print out just fine. i don't know what to do about that though

well, the environment the script runs in doesn't have it's own terminal, so no terminal size. (i guess).

0

Share this post


Link to post
Share on other sites
had you specified the shell at the top?

#!/bin/bash

yeah. see first post in thread.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0