I want to declare variable with pwd() function, which will give me the current path. I want to use pwd() function as ${pwd} variable, something like that. How I must write? Thanks!
I want to declare variable with pwd() function, which will give me the current path. I want to use pwd() function as ${pwd} variable, something like that. How I must write? Thanks!
Use command substitution:
Providing functions as parameters is not intended and will soon get tricky or ugly. The only way I know is via the eval function. Nykakins approach isn't passing a function, but a value, as you can see in this comparing example:
The first style evaluates the function 'date' before passing it's result to the client function f, as you can see, because the second time is before the third:
The second block shows, that the passed over function is evaluated between the two date-calls in the e-function.
Maybe you hadn't that strict naming convention in mind, when asking for a function as variable, but I would say that this makes the difference between a function as variable and the result of a function as variable.
Bash doesn't implement it but otherwise what you are precisely asking for, i.e. use variables exactly as functions, is very simple to implement with ksh93 discipline functions, eg:
When executed, the previous script shows: