Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash Function -> Command not found

Tags:

bash

Hi gusy I am trying to learn Bash and cannot seem to get this basic script to work.

#!/bin/bash

function system_info
{    
    echo "function system_info"
}

$(system_info)

I get a function: command not found issue.

like image 260
Andy Avatar asked Sep 04 '13 10:09

Andy


2 Answers

Bash is trying to evaluate the string that is outputted by the system_info function. You'll want to try the following, which will just simply run the function:

system_info

or to store the outputted value to a variable:

value=$(system_info)
like image 176
Tim Cooper Avatar answered Sep 29 '22 13:09

Tim Cooper


You need to invoke the function by saying:

system_info

$(...) is used for command substitution.

like image 41
devnull Avatar answered Sep 29 '22 13:09

devnull