Rawstring
Rawstring

Reputation: 67

Print from another function

In order to save space on the codeline, I need to build a function to print out the info provided by another function, e.g:

# (1-1) Install APP
function installapp {
  echo "APP description goes here."
  echo "Installing..."
  xterm -e apt-get install app
  echo "APP Was Successfully Installed"
  echo "Run APP From The Menu"
  echo "Press Enter To Return To Menu"
  read input
}

What I would like to know is how I can turn it into something like this:

# (1-1) Install APP
function installapp {
  echo "APP description goes here."
  echo "Installing..."
  xterm -e apt-get install app
  echo -e "$done(APP)"
  read input
}

Where the $done() function has all the ending info quoted above.

Upvotes: 1

Views: 49

Answers (1)

tripleee
tripleee

Reputation: 189948

Are you looking for something like this?

installdone () {
    echo "$1 Was Successfully Installed"
    echo "Run $1 From The Menu"
    echo "Press Enter To Return To Menu"
}
installapp () {
      echo "APP description goes here."
      echo "Installing..."
      xterm -e apt-get install app
      installdone APP
      read input
 }

Notice the preference for POSIX-compatible function declarations (no function keyword, which is a rather useless Bashism) and the lack of a need to say echo "$(installdone APP)" when the function prints things just fine all by itself.

If this were my program, I'd also put read input in the done function (or probably omit it entirely; why would someone want that?) or perhaps refactor this more thoroughly to the point where the diagnostic chatter can be disabled entirely.

Upvotes: 2

Related Questions