Lets say I have a file called large. In the file is just a bunch of cal commands copied for about 100 lines. Is there a way to run something at the end of this file that will show the total number of inputs?

I know that I can display the inputs from the file using wc -l large.sh but I'm curious if there is a way to do it inside of the file itself.


$0 contains the path to the script itself. You can try running

wc -l < "$0"

If there's a cd command somewhere in the script, you'll need to capture the absolute path to the script first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.