1

Let's take a little example:

$ cat fu.sh
#!/usr/local/bin/bash

function lsl () {
   ls -1
}

function grps () {
  lsl | grep fu.sh
}

echo "This file is: `grps`"

Let's run it to see it works as we want:

$ ./fu.sh
This file is: fu.sh

So - we have function lsl which called from second function grps. Also - we called function grps alone at the end of script.

Here is a question - is there anything "unusual", "unsafe" or may be "irritant" and "not Feng Shui" - call function without any option or argument passed to it?

6
  • 2
    Your question is definitely not bash-specific, but no - there is nothing wrong with such a function, as long as the function does exactly what you intended for it to do. Commented Nov 19, 2013 at 19:11
  • 2
    there's nothing wrong with it. if you need a function and you don't need arguments, that's what you're going to use. Commented Nov 19, 2013 at 19:12
  • 2
    On a related note, avoid using both the function keyword and brackets (cf. here). Commented Nov 19, 2013 at 19:13
  • @mtth thanks a lot, don't know about it... Commented Nov 19, 2013 at 19:41
  • and the function is not very useful: if you rename your script to "foo.sh" and forget to edit the inside, it will be incorrect. You cuold just do: function grps () { echo "$(basename "$0")" ; } instead Commented Nov 19, 2013 at 20:27

1 Answer 1

1

No, there is noting wrong in the script. It will work properly. You need to go through basics of shell scripting.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.