Solved

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

Posted on 2011-03-14
2
274 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
2 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 500 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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 …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

770 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