shell從函式檔案裡呼叫函式

2021-09-07 06:16:53 字數 724 閱讀 1680

碰到乙個shell中函式呼叫的小問題,記錄一下。

shell中函式有三種呼叫方式,一種是在檔案前面定義函式,然後在以下直接呼叫;一種是通重載入shell,在shell中直接呼叫;第三種是將函式寫入檔案。然後在其它shell中呼叫函式。

這裡寫一下關於第三種方法的樣例:

is_it_a_directory()

error_msg()

這個檔案定義了兩個函式,我們在以下的shell中呼叫者兩個函式,這裡有一點須要注意,在呼叫之前,要載入函式檔案。載入的方式為 . /路徑。注意有個空格

#!/bin/sh

. functions.sh

echo -n "enter destination directory :"

read direc

if is_it_a_directory $direc

then :

else

error_mag "$direc does not exist...creating it now"

mkdir #direc > /dev/null 2>&1

if [ $? != 0 ];

then

error_msg "could not "

exit 1

else :

fifiecho "extracting files..."

函式呼叫裡的 和

一般來說,無論是函式呼叫還是宣告,單個星號表示元組 或是列表 出現 而兩個星號則代表附近有字典 出沒 函式呼叫裡的 和 check web server host,port,path 用check web server 127.0.0.1 80,admin 即可呼叫和這個函式。那要是這些資訊在乙個三...

檔案呼叫函式

fopen fread fwrite fclose fseek fgets fputs fgetc fputc open read write close lseek file fopen const char filename,const char flag int open const char...

函式柯里化 函式鏈式呼叫 lazyman

實現鏈式呼叫實現 add函式,add 1 2 3 4 輸出10,然後考慮拓展性 解析為add 1 返回函式a,a 2 返回函式b,b 3 返回函式c function add num 但是如果鏈式呼叫加長,這種方法顯然不能滿足需求 改進 function add num return func 這樣...