• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

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

./test.sh 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
#!/bin/sh
sort $0

Open in new window

0
nocturn4l
Asked:
nocturn4l
1 Solution
 
TintinCommented:
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 ./test.sh

You need to use $1

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now