Как проверить, является ли данный путь файлом или каталогом

Другой вариант:

perl -lne 'print $1 while /<(.*?)>/g'

Захват скобок в $ 1 , . *? делает совпадение не -жадно, т.е. останавливается, как только может.

С awk :

awk -F'<' '{ for(i = 2 ; i <= NF ; i++) { sub(/>.*/, "", $i); print $i; } } ' 

Разделить строку на <, игнорировать первую часть, вывести остальные после удаления всего, что начинается с > . Это напечатает оставшуюся часть строки, если нет > после <.

1
20.06.2017, 13:14
1 ответ

У вас, видимо, есть ответ в комментариях. Я бы написал ваш код так, что избавляет от необходимости обращаться к вашим сценариям timeи check.sh. Это также уменьшает дублирование кода.

#!/usr/bin/expect

# assign command line arguments to variables
#  First Argument is Ip Address
#  Seond Argument is UserName
#  Third Argument is Password
#  Fourth Argument is Path to the source File to be copied (Keeping in mind that this path is concatenated with the second path in the program)
#  Fifth Argument is the destination path

lassign $argv ip user password file1 file2

set start [clock milliseconds]

set scp_args {-p}

if {[file isdirectory $file1]} {
    puts "It is a directory"
    lappend scp_args "-r"
    set c [exec find $file1 -type f | wc -l]

} elseif {[file isfile $file1]} {
    puts "It is a file"
    set c 1

} else {
    puts "$file1 is a [file type $file1]"
    exit 1
}

puts "Number of Files to be copied: $c"

#Set the timeout time for scp command
set timeout 5

#Executes the scp command
spawn scp {*}$scp_args $file1 $user@$ip:$file2

expect "password:"
send "$password\r"

expect eof
close

set end [clock milliseconds]
set elapsed [expr {($end - $start) / 1000.0}]
puts [format "duration: %.3f seconds" $elapsed]
1
27.01.2020, 23:45

Теги

Похожие вопросы