Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-03-14
2
Medium Priority
?
294 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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

618 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