#!/bin/bash
if [ $# -eq 0 ] then echo "please enter some arguments" fi x=$# ---now how to proceed |
#!/bin/bash
if [ $# -eq 0 ] then echo "please enter some arguments" fi x=$# ---now how to proceed |
hint:rev
|
Quote:
If you bothered to look at the bash scripting tutorial I posted to you before (or if you showed ANY effort into looking things up before you came here), you'd have had your solution. Again, we will spoon-feed you an answer: http://tldp.org/LDP/abs/html/interna...s.html#ARGLIST It shows you how to read multiple command-line arguments, and print them out. And 'rev' was mentioned...look it up. |
Code:
x=$@ # copy parameters to variable x |
Quote:
Code:
$./test.sh 1 2 13 5 4 |
I know. Sed would be more appropriate.
|
I did it with rev too, but with more lines.
I'd be interested to know whether there's a way to do it without rev or any loops. |
This works without rev and loops the last number is also reversed but changing that is trivial.
Code:
echo 182 3 6 7 81 |tr ' ' '\n' | sed -n '1!G;h;$p' |tr '\n' ' ' ; echo |
I was just thinking: why not concatenate all of the arguments to a single line and then sort that line?
Googled for how to sort items on a single line and got this: http://www.unix.com/302353987-post2.html Sort has a switch (finding it is your problem) that will cause it to sort in numerical order rather than lexical order. You should know how to get all of the arguments on a single line from following this discussion alone. I've just told you how to solve this. You're welcome. |
All arguments on one line is trivial
Code:
x=$@ Code:
xargs -n 1 |
Code:
|
Could you please edit the thread title to be more descriptive and appropriate to your problem? Say, "bash: sorting the arguments"?
|
Your programs gives problems with more then 10 parameters. A little adaptation.
Code:
#!/bin/bash |
Uhm, whizje, are you sure you should be trying to actually give him a a complete answer in the form of code? Remember that this is homework.
|
All times are GMT -5. The time now is 10:56 AM. |