How to call bash functions
Problem
Maybe I am looking at this the wrong way.. But here I what I am trying to do. Do most of my work with Java but just switched to a unix (bash) environment. I am doing this: But I have two functions in my file and I want to be able to call them separately from the command line. Ie: or even just . I know that I can add the functions to my file but is there any other way that I can execute these functions without adding them to my ?
Error Output
[~/Desktop/bashPlay]% cat myFunc
#!/bin/bash
ls2(){
echo "Hello World"
}
ls3(){
echo "Testing"
}
echo "this is a test"
ls2 # this calls a function
[~/Desktop/bashPlay]% myFunc
this is a test
Hello WorldUnverified for your environment
Select your OS to check compatibility.
1 Fix
Fix for: How to call bash functions
One way to do this, that involves a bit more typing, is via the command. To call a function from myFunc you could use and it would output Hello World. So for example, I have a file called : now I want to call it's function from the command line: to call it from another bash script: You can also put each in a separate script and add them in a directory which is in your PATH variable. so for example, in one script called you'd have: now put it in one of the directories in your PATH, which you can…
Awaiting Verification
Be the first to verify this fix
Sign in to verify this fix