Help in writing a script

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help in writing a script
# 1  
Old 10-07-2009
Help in writing a script

Hey everyone
Can anyone please write me a script to display numbers in descending order dynamically i.e if the user enter a number say 100 then the output should be like 100 99 on till 0
I tried using the logic as for ((i =1; i<=100; i--) but the it goes into a infinite loop since even the negative numbers are less than any given postive number entered by a user
# 2  
Old 10-07-2009
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
# 3  
Old 10-07-2009
This isn't a homework problem iam new to Linux and shell scripting altogether and besides iam new to programming too i recently joined as an intern in QA department of voip company.If this still isnt the proper section to post it,Iam sorry and i will see that i wont repeat such mistakes in the near future
sorry again
# 4  
Old 10-07-2009
for ((i=100;i>=0;i--));do echo $i;done
# 5  
Old 10-07-2009
Using "standard" linux "tools"

echo "Enter a number: "
seq 0 ${NUMBER:-100} | tac

# 6  
Old 10-07-2009
Originally Posted by scottn
Using "standard" linux "tools"

echo "Enter a number: "
seq 0 ${NUMBER:-100} | tac

seq is not standard, though it is common; tac is not standard and is less common than seq.

But you don't need tac if you are using seq:

seq NUMBER -1 0

The standard way is:

read n
while [ $n -ge 0 ]
  printf "%d\n" "$n"
  n=$(( $n - 1 ))

In bash:

eval "printf '%d\n' {$NUMBER..0}"

# 7  
Old 10-07-2009
I'm finding it increasingly difficult as I move from "proper UNIX" to linux to know what is standard.

There are just so many distributions of Linux about that all bets are off as to what versions of what anyone might have.

On AIX for example, "grep -p" is great for extracting stanzas (paragraphs) from files. But that's not standard I guess as GNU grep doesn't have it.

Add to that finds maxdepth, sed's in-place replacement... etc., etc.

Live and learn.

forgot to mention the worst one, echo -n (or echo minus anything)

Last edited by Scott; 10-07-2009 at 07:24 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I need help writing this script

:wall: Can't seem to figure out how to fix this please help its not starting over like I would like it to When I enter in "Date" or "Time" nothing comes Also if you can tell me the commands for the other 3 stuff that would be much appreciated #!/bin/bash clear while ; do echo... (8 Replies)
Discussion started by: nowruzr
8 Replies

2. Shell Programming and Scripting

Help in writing script

i need some help in donig some actions on files in a library. i want to get the n last files, and print to the screen their name, date, and how many times a specific string appears in each file.. how can i do this..?... (6 Replies)
Discussion started by: eee
6 Replies

3. Red Hat

writing a script

Dear Madam/Sir Who can help me with writing a script doing the following? 1- Read names of files (only files with special name format let say initially they have the same file name start like TT*) 2- Then create an empty files with the same names have been read in step one but with extension... (1 Reply)
Discussion started by: m.nageeb
1 Replies

4. Shell Programming and Scripting

Please help me in writing my script

hello all, I have a script, used to search for the strings from the set of 5 similar pattern file from the log dir. So here it goes . The input parameter is a part of the file name. When during the script execution, the script should parse the input parameter to original file's with the same... (0 Replies)
Discussion started by: baraghun
0 Replies

5. Shell Programming and Scripting

Help me in writing the script

Hi, I have written a script which converts a give hexdecimal value to binary value in perl. But now, the problem is I should read every bit of it ( if its 10101010, i should read the value in each position and if the value in that position is 1 i should print a string and should exit if its... (1 Reply)
Discussion started by: prakashreddy
1 Replies

6. UNIX for Dummies Questions & Answers

Need help writing this script

Here is the script I am trying to write along with my answer I wrote. Please help me understand why it doesn't work. Create an executable script file called "newname" that will perform the followings: 1. Rename a file upon the user's request. If the file exists, prompt the user for... (1 Reply)
Discussion started by: wiggles
1 Replies

7. Shell Programming and Scripting

help writing script

hi all i am having a file(a fixed length file) of 28 bytes.The file has account number from 5th place to next 16 digits. the file looks like below, 58331600563588885696ACXT5263 58331600563588885697ACXT5263 58331600563588885698ACXT5263 i want to write a script which will extract the... (8 Replies)
Discussion started by: dr46014
8 Replies

8. UNIX for Dummies Questions & Answers

help for writing a script

Hi, I need help writing a unix script to change the time in the server automatically when it reaches a specified time. Only on the 14th of april, when the time becomes midnight (00:00:00), I need the server to change the time automatically to 23:30:00 and start working on as usual with a... (2 Replies)
Discussion started by: amodha
2 Replies

9. Shell Programming and Scripting

Writing Script?

Anyone have an example of a simple shell script that solicits a (Y)es or (N)o response from the user. If the response is 'Y' display a message on the screen that thanks the user for the positive response. If the response is 'N' display a message that thanks the user for the negative response. If... (15 Replies)
Discussion started by: wmosley2
15 Replies

10. Shell Programming and Scripting

need help writing a script

Hello everyone. Well, I will get right to the point. I am new to Perl and trying to learn it as much as I can. I have been assigned the task of writing a perl script to extract information from firewall logs. Like I said, I am new to Perl and I am having a tough time because I think what I am... (3 Replies)
Discussion started by: tarballed
3 Replies
Login or Register to Ask a Question