FG

How can I invoke a function in bash shell script

Fresh3 days ago
Mar 15, 20268184 views
Confidence Score0%
0%

Problem

I just wonder the distinction calling the function between and in bash shell script. When I set the variable in , I can't invoke the function by ex:

Error Output

export PS1="\n\[\e[31m\] \$(one_func)  # it works 

export PS1="\n\[\e[31m\] one_func      # it doesn't work

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: How can I invoke a function in bash shell script

Low Risk

Contrary to how variables are accessed, functions are invoked by name without preceding the name with a '$'. You might be confused about how on the command line, you can define a function and invoke that function by name, but in your PS1 you had to …

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment