如何使用shell脚本中的函数将值/消息从一个脚本返回到另一个脚本?

如何使用shell脚本中的函数将值/消息从一个脚本返回到另一个脚本?,shell,Shell,我需要调用一个shell脚本,然后它将调用另一个shell脚本,在这个脚本中实现实际的逻辑 例如,两个脚本first.sh和second.sh 当我调用first.sh时,它将执行second.sh 在second.sh中,定义了使用ftp凭据登录的代码。我想使用函数将状态消息发送/返回到first.sh,以确定登录是否成功 我不知道shell脚本,有人能给我推荐上面场景的代码片段吗?执行此操作的标准方法是使秒。sh返回零/非零退出状态(对于OK,使用退出0,对于FAILURE,使用退出1),然

我需要调用一个shell脚本,然后它将调用另一个shell脚本,在这个脚本中实现实际的逻辑

例如,两个脚本
first.sh
second.sh

当我调用
first.sh
时,它将执行
second.sh

second.sh中,定义了使用ftp凭据登录的代码。我想使用函数将状态消息发送/返回到
first.sh
,以确定登录是否成功


我不知道shell脚本,有人能给我推荐上面场景的代码片段吗?

执行此操作的标准方法是使
秒。sh
返回零/非零退出状态(对于OK,使用
退出0
,对于FAILURE,使用
退出1
),然后首先在
中测试退出状态。sh

 #!/bin/sh
 #   first.sh

 ...
 if second.sh; then
     printf '%s\n' "Login went swimmingly"
 else
     printf '%s\n' "Uh-oh, somehow login failed"
 fi
连同

 #!/bin/sh
 #    second.sh

 ...
 if login using ftp worked; then
    exit 0
 else
    exit 1
 fi

执行此操作的标准方法是使
second.sh
返回零/非零退出状态(对于OK,使用
exit 0
,对于FAILURE,使用
exit 1
),然后在
first.sh中测试退出状态:

 #!/bin/sh
 #   first.sh

 ...
 if second.sh; then
     printf '%s\n' "Login went swimmingly"
 else
     printf '%s\n' "Uh-oh, somehow login failed"
 fi
连同

 #!/bin/sh
 #    second.sh

 ...
 if login using ftp worked; then
    exit 0
 else
    exit 1
 fi

查看
source
命令(您可以使用
source file2
.file2
)查看
source
命令(您可以使用
source file2
.file2