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

 

posted @ 2022-04-16 18:34  小鲨鱼2018  阅读(545)  评论(0编辑  收藏  举报