如何使用shell脚本中的函数将值/消息从一个脚本返回到另一个脚本?
我需要调用一个shell脚本,然后它将调用另一个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),然
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
)