Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Expect : what is the equivalent to ksh if -s

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 08-15-2013
popeye's Unix or Linux Image
popeye popeye is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 16 July 2015, 11:05 AM EDT
Posts: 94
Thanks: 23
Thanked 2 Times in 2 Posts
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 Unix and Linux 08-15-2013
in2nix4life's Unix or Linux Image
in2nix4life in2nix4life is offline
Registered User
 
Join Date: Oct 2007
Last Activity: 28 July 2015, 9:28 PM EDT
Location: East Coast
Posts: 620
Thanks: 1
Thanked 177 Times in 163 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 Unix and Linux 08-15-2013
popeye's Unix or Linux Image
popeye popeye is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 16 July 2015, 11:05 AM EDT
Posts: 94
Thanks: 23
Thanked 2 Times in 2 Posts
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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 01:26 PM.