... All is in the title.
Code: Select all
function 1 () {
[...]
function 2 () {
[...]
} End of 2
} End of 1
Code: Select all
} End of 2
} End of 1
Code: Select all
{ End of 2
{ End of 1
Cordialement.
Code: Select all
function 1 () {
[...]
function 2 () {
[...]
} End of 2
} End of 1
Code: Select all
} End of 2
} End of 1
Code: Select all
{ End of 2
{ End of 1
Code: Select all
func2() { echo "$1 World" ; }
func1() { echo `func2 Hello` ; }
ret=`func1`
echo $ret
sunburnt wrote:Not that I know of, can only call one from the other.Shell functions and loops are a royal pain.Code: Select all
func2() { echo "$1 World" ; } func1() { echo `func2 Hello` ; } ret=`func1` echo $ret
You can only export into them and echo back out of them.
Now if Bash had an option to run functions and loops in the same shell...
Code: Select all
$ while [ -z "$I" ]; do export I="true"; done
$ echo $I
true
$ testfunc() {
export I="$1"
}
$ testfunc garbaage
$ echo $I
garbaage
$ testfunc1() {
testfunc2() {
echo "Testing $2"
}
testfunc2 "$1"
}
$ testfunc1 abc def
Testing
Code: Select all
# func() { a=1 ; } ; func ; echo $a
1
# func() { b=2 ; }
# func
# echo $b
2
Code: Select all
# func1 () {
> a=1
> func2 () {
> b=2
> }
> }
# func1
# echo $a
1
# func2
# echo $b
2
Code: Select all
# func1 () {
> a=1
> func2 () {
> b=2
> }
> }
# func2
bash: func2: command not found
Code: Select all
# func1 () { a=1; echo $a; func2 () { b=2; echo $b;}; }
#
# func2
2
Code: Select all
# func1 () {
> a=1
> func2 () {
> b=2
> echo $b
> }
> }
# func2
2
#
I want to get values from functions I created inside an existing script I didn't create myself!amigo wrote:Don't nest the functions then.
No, this was just a simplified example to make you understand what I am expecting for. The original function is much more complicated in reality but it should work by following the same principles?I'm probably misunderstanding the question, but is the problem caused by the fact that the function itself does nothing apart from assign the variable (b=2).
Code: Select all
# Function tray app
function RUN_NOTIFICATION_TRAY () {
REFRESH_TEXT="$(gettext 'Refresh updates list')" ## refresh tray app text
REFRESH_ICON="/usr/local/lib/X11/mini-icons/gtk-refresh.png"
LOG_TEXT="$(gettext 'Log/Configuration files')" ## refresh tray app text
LOG_ICON="/usr/local/lib/X11/mini-icons/gtk-file.png"
CLEAR_TEXT="$(gettext 'Clear log files')" ## clear log files text
CLEAR_ICON="/usr/local/lib/X11/mini-icons/gtk-clear.png"
ABOUT_TEXT="$(gettext 'About')" ## about text
ABOUT_ICON="/usr/local/lib/X11/mini-icons/gtk-about.png"
HELP_TEXT="$(gettext 'Help')" ## help text
HELP_ICON="/usr/local/lib/X11/mini-icons/gtk-help.png"
QUIT_TEXT="$(gettext 'Quit')" ## exit tray app text
QUIT_ICON="/usr/local/lib/X11/mini-icons/gtk-quit.png"
PIPE_FIFO=$(mktemp -u $TEMP_DIR/update.XXXXXXXX)
## Function about
function about(){
export ABOUT="
<window decorated="false" skip_taskbar_hint="true">
<vbox border-width="10">
<hbox>
<button can-focus="no" relief="2"><input file stock="gtk-close"></input></button>
</hbox>
<frame 2POSou $APP_VERSION - $(gettext 'About') >
<pixmap><input file>/usr/share/pixmaps/2POSou.png</input></pixmap>
<text wrap="false" use-markup="true"><label>" <b><span size='large'>$(gettext 'Operating System Online Updater')</span></b>
$(eval_gettext '<i>(Argolance, adapted for $OS from POU-0.0.2 by ASRI
Original script by RSH for LazY Puppy - October 2013)</i>
<b>Localization:</b> <i>Argolance</i>
<b>Translations:</b>
')"</label></text>
<text use-markup="true" wrap="false" xalign="0">
<input file>$APP_DIR/translators</input>
</text>
</frame>
<frame $(gettext 'Links') >
<hbox>
<text><label>" $(gettext 'Report bugs and suggest improvements:') "</label></text>
<button tooltip-text=" $(eval_gettext 'If you have any questions or suggestions, or if you encountered a bug, please post a message on the $OS support Forum') "><input file>/usr/local/lib/X11/pixmaps/www24.png</input>
<action>defaultbrowser $FORUM &</action>
<action>exit:ok</action>
</button>
</hbox>
<hbox>
<text><label>" $(eval_gettext '$OS Web Site:') "</label></text>
<button tooltip-text=" $(eval_gettext 'Stay up to date with the latest news and programs published on the $OS website') "><input file>/usr/share/pixmaps/tooppy_logo.png</input>
<action>defaultbrowser $WEB_SITE &</action>
<action>exit:ok</action>
</button>
</hbox>
</frame>
</vbox>
</window>
"
gtkdialog4 --program=ABOUT --center
} # End of function
## Function default help file if locale help file doesn't exist
function help(){
if [[ ! -f $APP_DIR/help_files/2POSou_help_$lng2.html ]]; then
$BROWSER $APP_DIR/help_files/2POSou_help_en.html
else
$BROWSER $APP_DIR/help_files/2POSou_help_$lng2.html
fi
exit
} # End of function
## Function - Clear the history
function CLEAR_HISTORY (){
Xdialog --title "$(gettext 'Question')" --icon /usr/local/lib/X11/pixmaps/question.png --stdout --yesno "$(gettext 'Do you really want to clear log files?')" 0 100
case $? in
0)echo "`date "+%Y-%m-%d %H:%M:%S"`" - $(gettext 'Cleared by user') > $CONF_DIR/installed_updates_log
echo "`date "+%Y-%m-%d %H:%M:%S"`" - $(gettext 'Cleared by user') > $CONF_DIR/uninstalled_updates_log
echo "`date "+%Y-%m-%d %H:%M:%S"`" - $(gettext 'Cleared by user') > $CONF_DIR/downloaded_updates_log
echo "`date "+%Y-%m-%d %H:%M:%S"`" - $(gettext 'Cleared by user') > $CONF_DIR/excluded_updates_log
echo "`date "+%Y-%m-%d %H:%M:%S"`" - $(gettext 'Cleared by user') > $CONF_DIR/restored_updates_log
REFRESH_TRAY
Xdialog --title "$(gettext 'Information')" --icon /usr/local/lib/X11/pixmaps/info.png --left --no-buttons --infobox "$(gettext 'Log files cleared!')" 0 100
;;
1)Xdialog --title "$(gettext 'Information')" --icon /usr/local/lib/X11/pixmaps/info.png --left --no-buttons --infobox "$(gettext 'Clear log files cancelled!')" 0 100
;;
255)Xdialog --title "$(gettext 'Information')" --icon /usr/local/lib/X11/pixmaps/info.png --left --no-buttons --infobox "$(gettext 'Clear log files cancelled!')" 0 100
;;
esac
} # End of function CLEAR_HISTORY
## Function view log file
function OpenLogFile(){
$APP_DIR/log.sh &
} # End of function view log file
## close / quit menu
function CLOSE_QUIT () {
if [ "`pidof 2POSou_GUI.sh`" ]; then
kill $(ps ax | grep gtkdialog4 | grep PPOSou_GUI | awk '{print $1}' );
rm -f $CONF_DIR/run
fi
echo "0" > $CONF_DIR/tab
exec 3<> $PIPE_FIFO
echo "quit" >&3
rm -f $PIPE_FIFO
}
export -f CLOSE_QUIT
## Refresh tray app
function REFRESH_TRAY () {
if [ "`pidof 2POSou_GUI.sh`" ]; then
kill $(ps ax | grep gtkdialog4 | grep PPOSou_GUI | awk '{print $1}' );
echo -e '\c' > $CONF_DIR/run
else
rm -f $CONF_DIR/run
fi
$APP_DIR/AppRun &
CLOSE_QUIT
}
export -f REFRESH_TRAY
## 1 Create PIPE_FIFO file
mkfifo $PIPE_FIFO
export PIPE_FIFO
## 2 Attach a filedescriptor to this PIPE_FIFO
exec 3<> $PIPE_FIFO
## 3 Run yad and tell it to read its stdin from the file descriptor
GUI=$(yad --notification --auto-kill --listen --no-middle \
--image="$TRAY_ICON" \
--text="$POPUP_TEXT" \
--command="bash -c LEFT_CLICK" <&3) &
## 4 generate right click menu
echo "menu:$REFRESH_TEXT!bash -c REFRESH_TRAY!$REFRESH_ICON||$LOG_TEXT!bash -c OpenLogFile!$LOG_ICON|$CLEAR_TEXT!bash -c CLEAR_HISTORY!$CLEAR_ICON||$HELP_TEXT!bash -c help!$HELP_ICON|$ABOUT_TEXT!bash -c about!$ABOUT_ICON||$QUIT_TEXT!bash -c CLOSE_QUIT!$QUIT_ICON" >&3
} # End RUN_NOTIFICATION_TRAY
Code: Select all
while getopt ahv option ;do
case $option in
a) #about
about
;;
h) #help
[ .. ]
*) #do nothing
:
# do something
#echo choke me
#exit $quirk
;;
esac
done
Code: Select all
[ "$1" ]&& $@