小编kar*_*yan的帖子

sh return:只能从函数或源脚本"返回"

return语句错误:urn:只能从shell脚本 myscript.sh中的函数或源脚本"返回"

#!/bin/bash
if [ $# -ne 2 ]
then
    echo "Incorrect Usage : Arguments mismatch."
    return 2
fi

mv $1 $2

return 0
Run Code Online (Sandbox Code Playgroud)

当我试图跑

sh myscript.sh

Incorrect Usage : Arguments mismatch.
myscript.sh.sh: line 5: return: can only `return' from a function or sourced script
Run Code Online (Sandbox Code Playgroud)

如何解决这个错误?

linux bash shell operating-system

7
推荐指数
1
解决办法
6631
查看次数

标签 统计

bash ×1

linux ×1

operating-system ×1

shell ×1