few small scripting questions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting few small scripting questions
# 1  
Old 09-19-2006
few small scripting questions

hello everyone, i have a couple of questions about programming with shell scripts.

-My question is, how do you find out how long a sequence of numbers that has just been entered is. for example

If i enter 12345 the length here is 5
and 23456789 the length here is eight.

I want to be able to do an if statment that says if the string of numbers are a certain length do somthing, else do somthing.

-My last question, how do you tell your program that if you have a number, and you divide it by another number to do one thing if it divides evenly and something else if it is not? for example

lets say i have a while statement, and i want to say while the number i have is not evenly divisiable then display a message, but as soon as it can be evenly divided display a different message. And i do have a way of changing the number i am dividing by each time.

Thanks

Last edited by bebop1111116; 09-19-2006 at 04:53 PM..
# 2  
Old 09-19-2006
Quote:
Originally Posted by bebop1111116
hello everyone, i have a couple of questions about programming with shell scripts.

-My question is, how do you find out how long a sequence of numbers that has just been entered is. for example

If i enter 12345 the length here is 5
and 23456789 the length here is eight.

I want to be able to do an if statment that says if the string of numbers are a certain length do somthing, else do somthing.
doing 'man ksh' yields:
Code:
     ${#parameter}
           String Length. The length in characters of  the  value



SunOS 5.9           Last change: 24 Mar 2003                   14






User Commands                                              ksh(1)



           of  parameter.  If  parameter  is * or @, then all the
           positional parameters, starting with $1,  are  substi-
           tuted (separated by a field separator character).

Quote:
Originally Posted by bebop1111116
-My last question, how do you tell your program that if you have a number, and you divide it by another number to do one thing if it divides evenly and something else if it is not? for example

lets say i have a while statement, and i want to say while the number i have is not evenly divisiable then display a message, but as soon as it can be evenly divided display a different message. And i do have a way of changing the number i am dividing by each time.

Thanks
look into 'man bc' for the 'modulo' operand.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Scripting questions, remote access

Hi, Background: There are 2 servers server1 and server2 In server1 i have my script to perform a functionality from the script in server1 i m calling a script named action in server2. The script action has to check the size of a file in a particular location in server1, if the size of the file... (1 Reply)
Discussion started by: jayii
1 Replies

2. Shell Programming and Scripting

beginner scripting questions User variables

If there's anywhere to look this up, it would be just as helpful. I googled and really couldn't find anything relative to this. ok... General Variables 1) When creating a script I made a file "prog1.sh" does it matter if the end is .sh or is this what has to be done like prog.bash or... (4 Replies)
Discussion started by: austing5
4 Replies

3. Shell Programming and Scripting

need a small help

Hi, sorry for inconvenience..wrong query posted. Thanks for your help. Thanks (1 Reply)
Discussion started by: kirankumar
1 Replies

4. Homework & Coursework Questions

Scripting questions

I have two scripts and wish to finish the labs in two days, I am not sure how to make these work though. Any help would be appreciated, a step by step guide would be great! Q1) Complete the following instructions and submit the questions and answers from this lab to your tutor. Please... (1 Reply)
Discussion started by: noobie123
1 Replies

5. Homework & Coursework Questions

Print questions from a questions folder in a sequential order

1.) I am to write scripts that will be phasetest folder in the home directory. 2.) The folder should have a set-up,phase and display files I have written a small script which i used to check for the existing users and their password. What I need help with: I have a set of questions in a... (19 Replies)
Discussion started by: moraks007
19 Replies

6. Shell Programming and Scripting

Small help in scripting !!!

Hi all, I have a script in which line like this .. linux_ver="RHEL$(cat /etc/redhat-release | awk '{print $7}')" Result is linux_ver=RHEL5.3 But i want the o/p to be linux_ver=RHEL5 (discard ".3" or what ever comming after 5) please help me out Thanks in advance Renjesh... (4 Replies)
Discussion started by: Renjesh
4 Replies

7. Shell Programming and Scripting

Shell scripting questions

I have a file like this. Pls help me to solve this. 08-24-2010 10:22:34,xxxxxxxxMessage : 111 08-24-2010 10:24:38,xxxxxxxbMessage : 000 08-24-2010 11:28:11,xxxxxxxcMessage : 111 08-24-2010 11:32:35,xxxxxxxdMessage : 111 08-24-2010 11:32:35,xxxxxxxeMessage : 111 (I should look for Message... (1 Reply)
Discussion started by: mnjx
1 Replies

8. Shell Programming and Scripting

Need small help

Hi, i have a client requirement to post the files into generic folder named as "source".file identification is to retrieve Publication code (Instance name) from the file name.So thereafter we move the files to different instances of specific folders for the same unix server.(means if the file... (2 Replies)
Discussion started by: kirankumar
2 Replies

9. Shell Programming and Scripting

Shell/commands/scripting/c questions

1. Can anyone explain me what the line x=signal(SIGINT,nh); does? 2. How do I write a command to print the longest line in a file? 3. How do I write a command to print the last word of every line of a file using sed? 4. What exactly does this line do? :%s/^\(\)\(\)/\2\1/g^M... (3 Replies)
Discussion started by: Necrologist
3 Replies

10. UNIX for Dummies Questions & Answers

questions on ftp shell scripting

did a search but was not allowed to use 'ftp' because its too short of a word. for some reason, i can't seem to remember anything about ftp shell scripts - would someone please refresh my memory on the syntax and maybe give a short example? thanks for the time. (5 Replies)
Discussion started by: psyjoniz
5 Replies
Login or Register to Ask a Question