gpt4 book ai didi

linux - shell函数和参数传递问题

转载 作者:太空宇宙 更新时间:2023-11-04 10:42:33 25 4
gpt4 key购买 nike

<分区>

我需要将参数传递给 shell 脚本,经过验证后,需要将参数传递给脚本中的函数,无论是相同还是修改后。

#!/bin/sh
func1(){
echo "called func1 with $1" ;
exit 0 ;
}

func2(){
echo "called func2 with $1" ;
exit 0 ;
}

if [ $# -eq 0 ]
then
echo "Usage:" ;
echo "script.sh arg1 arg2" ;
exit -1 ;
fi

if [ "$1" -eq "txt1" ]
then
func1 $2 ;
exit 0 ;
fi

if ["$1" -eq "txt2" ]
then
func2 $2 ;
exit 0;
fi

我得到的响应是

sh script.sh txt1
sh: txt1: bad number
sh: txt1: bad number

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com