1#! /bin/sh 2# 3# @(#)return.sh 1.5 17/09/10 Copyright 2016 J. Schilling 4# 5 6# Read test core functions 7. ../../common/test-common 8 9if [ "$is_bosh" = true ]; then 10docommand r1 "$SHELL -c 'echo a; return; echo b'" 1 "a\n" IGNORE 11else 12echo "Skipping test r1 as this shell is $shell and not bosh and the behavior is unspecified" 13fi 14 15cat > x <<"XEOF" 16echo hi 17return 18XEOF 19docommand r50 "$SHELL -c 'fn() { . ./x; echo one; }; fn; echo two'" 0 "hi\none\ntwo\n" "" 20cat > test.dot <<"XEOF" 21fn() { 22 . ./x 23 echo one 24} 25fn 26echo two 27XEOF 28docommand r51 "$SHELL ./test.dot" 0 "hi\none\ntwo\n" "" 29 30remove x test.dot 31 32# 33# Check whether return only returns from function and not from dot script 34# as well. 35# 36cat > x <<"XEOF" 37f() { 38echo "In f" 39return 40} 41echo "Start" 42f 43echo "End" 44XEOF 45docommand r51 "$SHELL ./x" 0 "Start\nIn f\nEnd\n" "" 46 47remove x 48 49# 50# Check whether continue in a dot script does not cause 51# a return from the dot script. 52# 53cat > x <<"XEOF" 54echo "begin dot" 55x=0 56while [ "$((x+=1))" -le 3 ]; do 57 echo "$x" 58 continue 59done 60echo "end dot" 61XEOF 62docommand r51 "$SHELL -c '. ./x'" 0 "begin dot\n1\n2\n3\nend dot\n" "" 63 64remove x 65 66success 67