我想知道天气,可以从命令行和shell脚本中的函数传递参数
我知道它可以通过命令行来传递参数给shell脚本
$1 $2 ..
但是我的问题是我的shell脚本需要接受来自命令行的参数以及shell脚本中的函数。
在下面find我的shell脚本
Python读写tty
Bash Tab完成文件名后参数
pwd和/ bin / pwd的输出差异
如何执行“xargs”的反转?
#!/bin/bash extractZipFiles(){ sudo unzip "$4" -d "$5" if [ "$?" -eq 0 ] then echo "==>> Files extracted" return 0 else echo "==>> Files extraction Failed" echo "$?" fi } coreExtraction(){ extractZipFiles some/location some/other/location } coreExtraction echo "====> $1" echo "====> $2" echo "====> $3" echo "====> $4" echo "====> $5"
我通过传递来执行我的shell脚本
sudo sh test.sh firstargument secondargument thirdargument
使用* nix中的列命令格式化列表
使bash区分Ctrl- <letter>和Ctrl-Shift- <letter>
awk:通过特定的分隔符删除string
Linux命令来查找总磁盘和硬盘号码
您可以将原始参数转发给:
... coreExtraction () { extractZipFiles "$@" some/location some/other/location } coreExtraction "$@" ...
要从函数内部访问原始脚本参数,必须在调用函数之前将其保存起来,例如在数组中:
args=("$@") some_function some_other_args
在some_function ,脚本参数将在${args[0]} , ${args[1]} ,等等。 他们的电话号码将是${#a[@]} 。
coreExtraction "$1" "$2" "$3" # or coreExtraction "$@"
并添加其他参数给他们
extractZipFiles "$@" some/location some/other/location
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。