Страница 1 из 1

Подскажите с функцией

Добавлено: 2008-10-04 11:47:50
RusBiT
Подскажите как реализовать функцию ,

Код: Выделить всё

#!/bin/sh
DIR=/network
RESURS=ftp.ru
LOGIN=login
PASS=pass
#
FTP=ftp://$LOGIN:$PASS@$RESURS
DIR=$DIR/$RESURS
if [ "`mount | grep $DIR`" =  "" ] 
    then
	if ping -c 2 $RESURS
	then
	curlftpfs -o allow_other -o codepage=cp1251 $FTP $DIR
	fi
fi
Пробывал так, не работает

Код: Выделить всё

#!/bin/sh
ftp($LOGIN,$PASS,$RESURS,$DIR){
FTP=ftp://$LOGIN:$PASS@$RESURS
DIR=$DIR/$RESURS
if [ "`mount | grep $DIR`" =  "" ] 
    then
	if ping -c 2 $RESURS
	then
	curlftpfs -o allow_other -o codepage=cp1251 $FTP $DIR
	fi
fi
}
ftp("anonymous","mail@mail.mail","ftp.ru","/network");

Re: Подскажите с функцией

Добавлено: 2008-10-04 13:29:07
zg
в мануале как ни странно написано

Код: Выделить всё

   Functions
     The syntax of a function definition is

           name ( ) command

     A function definition is an executable statement; when executed it
     installs a function named name and returns an exit status of zero.  The
     command is normally a list enclosed between `{' and `}'.
функции вызываются как команды, обработка аргументов также как в обычных файлах $1, $2

Re: Подскажите с функцией

Добавлено: 2008-10-05 12:06:16
RusBiT
Спасибо, дошло

Код: Выделить всё

#!/bin/sh
FOLDER="/home/rbt/Рабочий стол/Network";
ftp (){
RESURS=$1;
LOGIN=$2;
if ["$LOGIN" = ""]
 then LOGIN="anonymous"; PASS="mount_script";
 fi
PASS=$3;
#
FTP=ftp://"$LOGIN":"$PASS"@"$RESURS"
DIR="$FOLDER"/"$RESURS"
if [ "`mount | grep $RESURS`" =  "" ] 
    then
	if ping -c 2 $RESURS
	then
	mkdir "$DIR";
	chown rbt "$DIR";
	curlftpfs -o allow_other -o codepage=cp1251 "$FTP" "$DIR"
	fi
fi
}
ftp "ftp.ru" "login" "pass";
ftp ftp2.ru