How can I sort a file in a function? Bourne Shell

I have a file I want to sort... which I'm able to do to directly at the command line by simply typing

sort file.txt for instance

but I'm trying to make a shell function that does the same thing.. for example if I type

./ file.txt

but I can't get it to work.. instead it's messing up my code directly for some reason.. or maybe i should be using something that's not "sort"? any help would be great, thanks
sort $0

Open in new window

Who is Participating?
TintinConnect With a Mentor Commented:
You're creating a shell script not a shell function (functions are generally contained within shell scripts)

$0 refers to the script, so in you case you would be trying to run

sort ./

You need to use $1

or $* if you want to specify multiple files.
nocturn4lAuthor Commented:
sigh i been trying to figure it out for like an hour and it was soo simple.. thank you
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.