Shell script Programming Function Chapter __php

Source: Internet
Author: User

Let's take a look at the return value of the two functions to get the way:

#!/bin/bash
#函数返回值获取测试.
function fun_test ()
{
    #在函数内部是不能有其他的任何一条打印语句.
    Echo
}
val=$ (fun_test) 
echo $val

Another one:

#!/bin/bash
#函数返回值获取测试.
function fun_test ()
{return
}
fun_test
val=$?
Echo $val
#!/bin/bash
#在当前目录下面创建多个不存在的目录.
function Create_dir ()
{ 
     mkdir./$1 >/dev/null
} while
[$#-gt 0];d o
    a= ' ls | grep ' $ '
    if [' $a ' = ' $ '];then
  echo "has exit!!!"
        Exit 0
    Else
    create_dir the
    fi
    shift 1
done
#/bin/bash
#递归求解1 + ...
sum=0
function fun_test ()
{
   If [$1-gt 0];then set-x let 
    sum+=$1
    set +x
    Fun_test $ (($1-1))
    else
       echo  $sum
    fi  
}
val=$ (fun_test)
echo $val
#!/bin/bash #打印指定目录中的所有目录文件. function Is_dir () {local dir=$1 if [-D ${dir}];then return 0 else return 1 fi} function L
    S_dir () {local dir=$1 arr= (' ls ${dir} ') #创建数组.
    CD $dir #跳转目录.
        for (i=0;i<${#arr [@]};i++)) {#遍历数组, it's important here. If [D-${arr[i]}];then echo "This is a dir:" ${arr[i]} else echo "This is ' t a dir:" ${arr[i

} fi} cd-#回到主进程目录. } proc=$ (basename $) proc= ' basename $ ' function usage () {printf "%s%s\n" "Usage:" "/${proc}dir" #如果没有传进入
parameter, the error message is returned to the user. } If [$#-ne 1];then usage exit 1 fi ls_dir $ 
#!/bin/bash #打印一个动态的进度条, did not realize the color change. Arr= ("|") "/"-"\ \") function Pro () {local i=0 str= ' while [$i-le] doing let index=i%4 printf ' [%s] [%d%%] [%c]\r "" $str "$i" ${arr[index]} "sleep 0.2 let i++ str=${str}# do} Pro 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.