gpt4 book ai didi

linux - 如何在 bash 脚本中将第一行用户类型读入终端

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

我正在尝试编写一个脚本,在其中运行该脚本,用户将按照

$./cpc -c test1.txt backup

进入终端,其中 ./cpc 是运行脚本,-c 是 $option,test1.txt 是 $source,backup 是 $destination。

我如何将输入的值分配给终端以在我的脚本中使用它们,例如

if [[ -z $option || -z $source || -z $destination ]]; then
echo "Error: Incorrect number of arguments." (etc)

在线检查脚本时返回以下错误:“选项/源/目标已被引用但未分配。”

如果其中任何一个没有意义,请提前道歉,我会尽可能清楚

最佳答案

参数存储在编号参数 $1$2 等中。因此,只需分配它们

option=$1
source=$2
destination=$3

另见 man getoptman bash 中的 getopts

关于linux - 如何在 bash 脚本中将第一行用户类型读入终端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36533170/

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