Expect : what is the equivalent to ksh if -s | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Expect : what is the equivalent to ksh if -s

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-15-2013
popeye's Avatar
popeye popeye is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 11 July 2014, 11:24 AM EDT
Posts: 84
Thanks: 16
Thanked 1 Time in 1 Post
Expect : what is the equivalent to ksh if -s

In Ksh to check if file exists and is non zero ..



Code:
if [ ! -s $FILE ];
then
        echo "Error $FILE does not exists!"
else
        echo "$FILE found!"
fi

Cant seem to find the Expect equivalent ....

Any help is greatly appreciated.
Sponsored Links
    #2  
Old 08-15-2013
in2nix4life's Avatar
in2nix4life in2nix4life is offline
Registered User
 
Join Date: Oct 2007
Last Activity: 25 September 2014, 11:53 AM EDT
Location: East Coast
Posts: 611
Thanks: 1
Thanked 176 Times in 162 Posts
In Expect you can use "file exists" and/or "file size" to get the status of a file:


Code:
#!/usr/bin/expect -f

set filename "/tmp/file"
set file_status [file exists $filename]
if { $file_status > 0 } {
    set retcode [file size $filename]
    puts "$filename exists and is $retcode bytes."
} else {
    puts "$filename not found!"
}

The Following User Says Thank You to in2nix4life For This Useful Post:
popeye (08-15-2013)
Sponsored Links
    #3  
Old 08-15-2013
popeye's Avatar
popeye popeye is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 11 July 2014, 11:24 AM EDT
Posts: 84
Thanks: 16
Thanked 1 Time in 1 Post
Thank you.

But I was playing around with this .. curious why its not working .. but I actually like your code. It reads better.



Code:
set fnam "/home/popeye/testfile"
send_user "$fnam\n"
expect {
          "$fnam" {
                     send_user "found\n"
                     }
           timeout {
                      send_user "not found\n"
                      }
}

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ksh equivalent to >& in csh kristinu Shell Programming and Scripting 18 11-05-2010 08:01 AM
calling expect script in ksh is failing via cron bhatia Shell Programming and Scripting 2 09-24-2009 06:00 AM
equivalent of backspace in ksh solaix14 Shell Programming and Scripting 2 03-30-2009 06:35 PM
what is ksh equivalent of bash echo -n ? mudhireddy Shell Programming and Scripting 3 12-15-2006 03:24 PM
Perl equivalent of ksh if / echo statement gefa Shell Programming and Scripting 2 02-17-2005 11:07 AM



All times are GMT -4. The time now is 08:14 AM.