Visit Our UNIX and Linux User Community


Variable explanation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Variable explanation
# 1  
Old 10-06-2009
Variable explanation

What does this part in the following code ?

if [ ".$t" != . ]; then
$t shows some time values for getting the response, but why .$t and what does the . after the !=

Code:
t=$(time -p wget --quiet --post-data='username=xxx&password=xxxx&id=xxxxxx' --no-check-certificate --output-document=/tmp/sms-status_out --timeout=30 "https://www.xxx.de/gsm/status.php" | perl -ne 'print int($1 * 1000) if /^real (\S+)/')
if [ ".$t" != . ]; then

thx

Alex
# 2  
Old 10-06-2009
Hi.

It's one way of showing if $t is set or not.

If t is not set then the statement would expand to

Code:
if [ . != . ]; then

which is false.

If t is set to, say A, then that becomes

Code:
if [ .A != . ]; then

which is true, thus if $t is set, the if statement is executed, otherwise the else part (iif one exists) is.
# 3  
Old 10-06-2009
OK, thx!
# 4  
Old 10-06-2009
Quote:
Originally Posted by locutus01
What does this part in the following code ?

if [ ".$t" != . ]; then
$t shows some time values for getting the response, but why .$t and what does the . after the !=

Code:
t=$(time -p wget --quiet --post-data='username=xxx&password=xxxx&id=xxxxxx' --no-check-certificate --output-document=/tmp/sms-status_out --timeout=30 "https://www.xxx.de/gsm/status.php" | perl -ne 'print int($1 * 1000) if /^real (\S+)/')
if [ ".$t" != . ]; then


It's a workaround for pre-POSIX shells.

It's a convoluted way of doing:

Code:
if [ -n "$t" ]


Previous Thread | Next Thread
Test Your Knowledge in Computers #941
Difficulty: Medium
A ping of death is a type of attack on a computer system that involves sending a malformed or otherwise malicious ping to a computer.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need explanation

Hi, I need more explination on it, how it works abcd="$(echo "$abcd" | sed 's/ //g')" >> ${LOGFILE} 2>&1 can any one suggest me on this? Rgds, LKR (1 Reply)
Discussion started by: lakshmanraok
1 Replies

2. Shell Programming and Scripting

Explanation for the variable

Hi, In the script, it's declared as like that. Please explain this one. pk.flags.summaryGrep=Timing Thanks (4 Replies)
Discussion started by: bmk
4 Replies

3. UNIX for Dummies Questions & Answers

If statement explanation

Could anyone please advise what the in the following if statement means? if ; then Thank you. (2 Replies)
Discussion started by: jimbojames
2 Replies

4. UNIX for Dummies Questions & Answers

Explanation on egrep

Hi all I am new to egrep can someone please explain me what does the below Statement do egrep -v "^missing sales|^\ Thanks in advance Sri Please use next time code tags for your code and data (4 Replies)
Discussion started by: Sri3001
4 Replies

5. UNIX for Dummies Questions & Answers

In need of explanation

Its great someone provided this script that strips out a filename and extension but can someone explain how each line works? file1='Jane Mid Doe.txt' newfile='Jane.txt' 1) ext=${file1##*.} 2) filename=${file%%.???} 3) set -- $filename 4) newfile="1.$extension" (1 Reply)
Discussion started by: Lillyt
1 Replies

6. Shell Programming and Scripting

Need explanation of script

Hi All, Can anybody explain what this script is doing? #!/bin/sh who | cut -d " " -f1 | sort -u > userlist1 while true ; do sleep 60 who | cut -d" " -f1 | sort -u >userlist2 for username in `cat userlist1` ; do if ! grep "^$username$" userlist2 > /dev/null ; then echo... (0 Replies)
Discussion started by: vishalpatel03
0 Replies

7. UNIX and Linux Applications

need explanation

Hi am having a c pgm. It has the include files (unistd.h,sys/types.h,win.h,scr.h,curses.h,stdarg.h and color.h). I don't know the purpose of these include files. will u plz explain me. (1 Reply)
Discussion started by: Mari.kb
1 Replies

8. Shell Programming and Scripting

tr explanation please

how does below tr command replace nonletters with newlines? I think I understand tr -cs '\n' part.. but what is A-Za-z\' <--- what is this?? tr -cs A-Za-z\' '\n' | -c --complement -s, --squeeze-repeats replace each input sequence of a repeated character that is... (1 Reply)
Discussion started by: convenientstore
1 Replies

9. Shell Programming and Scripting

tr explanation please

how does below tr command replace nonletters with newlines? I think I understand tr -cs '\n' part.. but what is A-Za-z\' <--- what is this?? tr -cs A-Za-z\' '\n' | -c --complement -s, --squeeze-repeats replace each input sequence of a repeated character that is... (0 Replies)
Discussion started by: convenientstore
0 Replies

10. Shell Programming and Scripting

AWK explanation

Hi, Could anyone please explain why we have arr=1 - what does this statement do? awk -F\; 'FNR==NR{arr=1;next};$3 in arr' core.txt gmrd.txt Any help appreciated (2 Replies)
Discussion started by: penfold
2 Replies

Featured Tech Videos