'Execute a Bash Function in new Xterm window
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
Solution 1:[1]
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" &
Solution 2:[2]
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" &
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Bib |
| Solution 2 | Bayou |
