?
Solved

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

Posted on 2011-03-14
2
Medium Priority
?
291 Views
Last Modified: 2012-08-13
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
Comment
Question by:nocturn4l
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 2000 total points
ID: 35134905
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
 

Author Comment

by:nocturn4l
ID: 35134922
sigh i been trying to figure it out for like an hour and it was soo simple.. thank you
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question