PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, October 19, 2022

[FIXED] How to call a function in a new terminal, inside a bash script?

 October 19, 2022     bash, function, terminal     No comments   

Issue

I've written a script in which I define a function and later I call that function in a new terminal. Something like this:

#!/bin/sh

my_func(){
  echo "hello world"
  sleep 5
}

alacritty -e my_func

But I got an error :

[ERROR] [alacritty_terminal] Failed to spawn command 'my_func': No such file or directory (os error 2)

I guess that new terminal doesn`t have access to the function I've defined inside the script. How can I get around this?


Solution

alacritty -e will run a Linux command and you are giving it a function as an argument so it will not work.

The only way to make it work is splitting it into two scripts. I called them echo.sh and function.sh.

echo.sh

echo "Hello man"
sleep 5

function.sh

#!/bin/sh
alacritty -e ./echo.sh


Answered By - iker lasaga
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing