Jump to content


Photo
- - - - -

interesting conundrum


  • Please log in to reply
7 replies to this topic

#1 neuro

neuro

    biggest post whore in history

  • Members
  • 2,047 posts

Posted 06 June 2004 - 01:48 AM

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 $COLUMNS
80
bash-2.05b$

when ran strait from the console, the number of columns is printed.
but in a teeny bash script:

#!/bin/bash
echo $COLUMNS

it doesn't do anything:

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

bash-2.05b$ 

why?

#2 replax

replax

    Hakker addict

  • Members
  • 505 posts

Posted 06 June 2004 - 02:10 AM

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.

#3 replax

replax

    Hakker addict

  • Members
  • 505 posts

Posted 06 June 2004 - 02:44 AM

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.

#4 neuro

neuro

    biggest post whore in history

  • Members
  • 2,047 posts

Posted 06 June 2004 - 11:49 AM

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.

#5 replax

replax

    Hakker addict

  • Members
  • 505 posts

Posted 06 June 2004 - 01:57 PM

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

#6 neuro

neuro

    biggest post whore in history

  • Members
  • 2,047 posts

Posted 06 June 2004 - 02:23 PM

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).

#7 profetas

profetas

    mad 1337

  • Members
  • 146 posts

Posted 06 June 2004 - 02:42 PM

had you specified the shell at the top?

#!/bin/bash

#8 neuro

neuro

    biggest post whore in history

  • Members
  • 2,047 posts

Posted 06 June 2004 - 03:31 PM

had you specified the shell at the top?

#!/bin/bash

yeah. see first post in thread.




BinRev is hosted by the great people at Lunarpages!