linux 中如何给shell函数传递参数


1、测试函数

[root@rhel7pc1 test]# ls
test.sh
[root@rhel7pc1 test]# cat test.sh    ## $1 为第一个参数, $2为第二个参数,其余以此类推
#!/bin/bash
function fun_test {
        seq $1
}

2、加载测试函数参数

[root@rhel7pc1 test]# source test.sh
[root@rhel7pc1 test]# fun_test 3   ## 传递第一个参数为3
1
2
3
[root@rhel7pc1 test]# fun_test 5   ## 传递第一个参数为5
1
2
3
4
5