Home > Software engineering >  Execute a Bash Function in new Xterm window
Execute a Bash Function in new Xterm window

Time:02-21

Is there a way one can execute the bash function in the new XTERM window? Below is what I am trying to do

function test(){
 echo "Do some work"
}

Then inside my bash script, I am doing the following:

export -f test
xterm -title "Work1" -e "test" "$date_today" "$time_today" &
# The above I am trying to open xterm, run the function, and pass 2 parameters (date_today and time today)

Currently the above does not work as it complains that test is not defined. Any help would be appreciated

CodePudding user response:

Don't put it in a function, just:

#!/bin/bash
echo "Do some work"

and name the file test.sh. Do NOT call it just test. Remember to chmod x file.sh. Then call it with:

xterm -title "Work1" -e "<path_to_file>/test.sh" "$date_today" "$time_today" &

CodePudding user response:

I use typeset to export functions through ssh, but it seems that you can use it for xterm as well.

$ function test(){
    echo "Do some work"
}

$ export -f test

$ xterm -title "Work1" -e "$(typeset -f test); test" "$date_today" "$time_today" &
  • Related