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\"
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)
#!/bin/bash
function system_info
{
echo "function system_info"
}
echo $(system_info)
Kind of redundant but it works without the command not found error.
Or This:
#!/bin/bash
function system_info
{
echo "function\n system_info"
}
printf "$(system_info)"
If you want to use newline character.
You can try this code in: https://www.tutorialspoint.com/execute_bash_online.php
Invoke the function inside the script with just the function name and execute the script from the shell
#!/bin/bash
function system_info {
echo "function system_info"
}
system_info
You need to invoke the function by saying:
system_info
$(...)
is used for command substitution.