#!/bin/bashset -xecho "This is an example of run another INTO this session."source my_lib_of_variables_and_functions.shecho "The function internal_function() is defined into my lib."returned_value=internal_function()echo $this_is_an_internal_variable
set +x
#!/bin/bash
# Here you define the absolute path of your script
scriptPath="/home/user/pathScript/"
# Name of your script
scriptName="myscript.sh"
# Here you execute your script
$scriptPath/$scriptName
# Result of script execution
result=$?
#!/bin/bashSUB_SCRIPT=$(mktemp)echo "#!/bin/bash" > $SUB_SCRIPTecho 'echo $1' >> $SUB_SCRIPTchmod +x $SUB_SCRIPTif [[ $1 == "--source" ]]; thenfor X in $(seq 100); doMODE=$(source $SUB_SCRIPT "source on")doneelsefor X in $(seq 100); doMODE=$($SUB_SCRIPT "source off")donefiecho $MODErm $SUB_SCRIPT
输出:
~ ❯❯❯ time ./test.shsource off./test.sh 0.15s user 0.16s system 87% cpu 0.360 total
~ ❯❯❯ time ./test.sh --sourcesource on./test.sh --source 0.05s user 0.06s system 95% cpu 0.114 total