Register
It is currently Tue Oct 21, 2014 9:09 am

bash environment vars -_-


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Tue Oct 05, 2010 5:49 pm   

Joined: Tue Oct 05, 2010 5:34 pm
Posts: 3
#!/bin/bash

old_rows=$ROWS # then old_rows=20
old_columns=$COLUMNS # then old_columns=70

resize -s 24 108 >/dev/zero
netstat.bin $* |less
resize -s $old_rows $old_columns #BUT old_rows=24 and old_columns=108 ┬┐What happend?

# I don't know..
# pointer???????
# any help or reference?


Top
 Profile  
 PostPosted: Tue Oct 05, 2010 11:38 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
I assume you wanted to post in the Requests part of the forum...

I don't know what OS you're working on, but on linux its not $ROWS but $LINES and not netstat.bin but just netstat and we don't redirect output to /dev/zero because that's an output device but to /dev/null because it accepts input

Anyways, I ran the script with these modifications and it worked like a charm. Here's the output of the script with set -x:
Code:
$>cat ./test.sh
#!/bin/bash
set -x

old_rows=$LINES
old_columns=$COLUMNS

resize -s 24 108 >/dev/null
netstat $* | less
resize -s $old_rows $old_columns >/dev/null

$>./test.sh
+ old_rows=42
+ old_columns=167
+ resize -s 24 108
+ netstat
+ less
+ resize -s 42 167


Top
 Profile  
 PostPosted: Wed Oct 06, 2010 12:16 am   

Joined: Tue Oct 05, 2010 5:34 pm
Posts: 3
Hi Patsie,
I do not speak much English so I was confused when exposed here, sorryyyy.

my OS is debian squeeze/sid
ROWS to LINES : you're right
netstat.bin: my own script
/dev/zero: data sink for resize output

running your script
Code:
[nothing_user[01:47 AM][~]]$ cat ./test.sh
#!/bin/bash
set -x

old_rows=$LINES
old_columns=$COLUMNS

resize -s 24 108 >/dev/null
netstat $* | less
resize -s $old_rows $old_columns >/dev/null

[nothing_user[01:47 AM][~]]$ ./test.sh
+ old_rows=
+ old_columns=
+ resize -s 24 108
+ less
+ netstat
+ resize -s

can you see that?? old_rows and old_columns are empty!!!
I don't know what happend
I think both script should be work


Top
 Profile  
 PostPosted: Wed Oct 06, 2010 1:06 am   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
Apparently the environment vars $LINES and $COLUMNS are not available from your script. This could be because they are not set or because they are not exported. Either way, since you are already using the 'resize' command, I suggest using that to save and restore your settings:
Code:
#!/bin/bash

save="$(resize)"

resize -s 24 108 >/dev/null
netstat $* | less

eval "$save"


Top
 Profile  
 PostPosted: Wed Oct 06, 2010 10:06 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 550
I like what the man page shows
Code:
#!/bin/bash

resize > /tmp/out

resize -s 24 108 >/dev/null
netstat $* | less

source /tmp/out


Top
 Profile  
 PostPosted: Wed Oct 06, 2010 11:32 am   

Joined: Tue Oct 05, 2010 5:34 pm
Posts: 3
Don't work for me :(

I tested it on a linux live edition and does not work.
This is a bit weird because I did in c/c++ and all is well. Did not put the code here because it is a bash forum :) :D


Thanks for the answers.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP