testing variables issue


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers testing variables issue
# 1  
Old 12-01-2011
testing variables issue

oh,i don't understand
my shell file like this
Code:
#!/bin/sh
#
#
testnum=$(ifconfig eth0|sed -n 8p|awk '{print $2}'|cut -c7-)
echo $testnum
sleep 2
echo $testnum
sleep 2
echo $testnum
sleep 2
echo $testnum

but the output was always the same value
like
Code:
[root@localhost test]# ./test.sh
3779052732
3779052732
3779052732
3779052732

why?
# 2  
Old 12-01-2011
The same reason this never changes:

Code:
testnum="qwertyuiop"
echo $testnum
sleep 2
echo $testnum
sleep 2
echo $testnum
sleep 2
echo $testnum

The value of "qwertyuiop" is copied into the variable and doesn't change until you set it to anything else.
# 3  
Old 12-01-2011
ok,i know you means,thank you
that’s difference
if the variable need to return the lastest value,i must recall it,right?
# 4  
Old 12-01-2011
Code:
echo $(ifconfig eth0|sed -n 8p|awk '{print $2}'|cut -c7-)
sleep 2
echo $(ifconfig eth0|sed -n 8p|awk '{print $2}'|cut -c7-)
sleep 2
echo $(ifconfig eth0|sed -n 8p|awk '{print $2}'|cut -c7-)
sleep 2
echo $(ifconfig eth0|sed -n 8p|awk '{print $2}'|cut -c7-)

Or better:

Code:
echo $(ifconfig eth0|sed -n 8p|awk '{print $2}'|cut -c7-)
for X in 1 2 3
do
        sleep 2
        echo $(ifconfig eth0|sed -n 8p|awk '{print $2}'|cut -c7-)
done

This User Gave Thanks to Corona688 For This Post:
# 5  
Old 12-01-2011
thank you very much!
i think this unix forum is the most rigorous forum i had ever see,which make a big difference with China
thanks Corona688
ps:sorry for my poor english ^_^

---------- Post updated at 08:48 PM ---------- Previous update was at 08:18 PM ----------

do i need to do something to close this thread
# 6  
Old 12-02-2011
There is nothing like close in this forum.

I think, you can ignore the sed command also.

Code:
 
for X in 1 2 3
do
 echo $(ifconfig eth0|awk 'NR==8{print $2;exit}'|cut -c7-)
 sleep 2
done

This User Gave Thanks to itkamaraj For This Post:
# 7  
Old 12-02-2011
ifconfig eth0|awk 'NR==8{print $2;exit}'|cut -c7-
it also the same result when i run the command like this
ifconfig eth0|awk 'NR==8{print $2}'|cut -c7-
can u tell me the effect of ";exit" ?



 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue nesting variables in csh.

The variables given are already defined ($file1-$file3, $obsid1-$obsid3, and $n=3). When I go to run the code, the terminal outputs "Missing }." I believe the error is with the nesting of variables. It would save a lot of time getting this while loop working. set i = 1 while (${i} <=... (5 Replies)
Discussion started by: ojdefdidit
5 Replies

2. Solaris

Solaris 8 ssh issue - $SSH_ORIGINAL_COMMAND undefined variables

I face a weird question I don't know how to deal with. I tried to limit the permission of root user to remote login using ssh. So I did the following for a client server, 1. edit /usr/local/etc/sshd_config and modify as below PermitRootLogin forced-commands-only 2. using pubkey... (7 Replies)
Discussion started by: bestard
7 Replies

3. Shell Programming and Scripting

Issue in shell script variables

Hi, I have a file at $HOME/t.txt, below is file content cat $HOME/t.txt CUSTOMER_${REGION}.out Am using this file content in one script $HOME/samp.sh, below is the script #!/bin/bash REGION=USA x=`cat ${HOME}/t.txt` echo $x Am getting following output.. CUSTOMER_${REGION}.out ... (3 Replies)
Discussion started by: shieksir
3 Replies

4. Shell Programming and Scripting

Scripting Issue with Variables from awk

Greetings all, Disclaimer: I'm a novice and always welcome best practices as I'm learning. File example: 100,1.1.1.1,1.1.1.2,10.10.10.1,172.16.1.10,172.16.1.20 101,1.1.2.1,1.1.2.2,10.10.20.1,172.16.2.10,172.16.2.20 102,1.1.3.1,1.1.3.2,10.10.30.1,172.16.3.10,172.16.3.20 ...and so on ... (3 Replies)
Discussion started by: sjrupp
3 Replies

5. Shell Programming and Scripting

awk issue expanding variables in ksh script

Hi Guys, I have an issue with awk and variables. I have trawled the internet and forums but can't seem to get the exactt syntax I need. I have tried using awk -v and all sorts of variations but I have hit a brick wall. I have spent a full day on this and am just going round in circles. ... (3 Replies)
Discussion started by: gazza-o
3 Replies

6. Shell Programming and Scripting

Awk script problem - Variables Causing Issue

can someone please explain to me what i'm doing wrong with this code: WELT=$(awk '(($1 ~ "^${caag}$") || ($2 ~ "^${caag}$"))' /tmp/Compare.TEXT) when run from the command line, it works. but it seems to be having a problem doing the comparison when variables are involved. i tested from... (1 Reply)
Discussion started by: SkySmart
1 Replies

7. Shell Programming and Scripting

White spaces issue with shell variables

Hi all, I've a requirement as below Source file src.txt sample data: A<10 white spaces>B12<5 white spaces>C<17 white spaces> A1<5 white spaces>B22<5 white spaces>C13<17 white spaces> when I'm fetching a record from this file into a shell variable like below: vRec=`head -1 src.txt... (2 Replies)
Discussion started by: madhu_1126
2 Replies

8. UNIX for Dummies Questions & Answers

Issue with variables via cronned script

I have script sourcing the profile of functional user like as below and my .profile for functional user has below entry now when i cron the script i am receiving the below error after execution, though i could see the output of variable when i do echo as below. can you tell me where... (11 Replies)
Discussion started by: Ariean
11 Replies

9. UNIX for Dummies Questions & Answers

Issue with parsing config variables

I am using MKS tool kit on windows server. One config variable is defined in windows environment and I am trying to use that variable. # Below RootDir is defined in windows RootDir="\\f01\var" # in unix script details="$RootDir/src|$RootDir/tgt" src=`echo $details|awk -F '|' '{print... (1 Reply)
Discussion started by: madhukalyan
1 Replies

10. Programming

How to convert byteArray variables to HexaString variables for Linux?

Hello everybody, I am having problem in converting byte array variables to Hexa String variables for Linux. I have done, converting byte array variables to Hexa String variables for Windows but same function doesn't work for linux. Is there any difference in OS ? The code for Windows is given... (2 Replies)
Discussion started by: ritesh_163
2 Replies
Login or Register to Ask a Question