Sponsored Content
Full Discussion: Filter command arguments
Homework and Emergencies Homework & Coursework Questions Filter command arguments Post 302660791 by Learn4Life on Saturday 23rd of June 2012 06:41:51 AM
Old 06-23-2012
Filter command arguments

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

Execute command with integer list arguments such as myScript 8 7 2 3.
Take those arguments and square all of them one by one, each iteration print out the result. At the end print out the total sum of the squared values.

2. Relevant commands, code, scripts, algorithms:
Code:
# Error handling if the argument list is empty or contains string instead of integers.

if [ $# = 0 ]
then
        echo "Usage $0 -integer-list"
        exit 1
elif [ $@ = [^9-0] ]
then
        echo "No Strings are allowed."
fi

I want to output an error message when characters are found inside the argument list.


3. The attempts at a solution (include all code and scripts):
Code:
#!/bin/sh
# File:                         power
# Author:                      
# Student ID:                   
# Created:                      6/23/2012
# Purpose:                      
# Description:                  This program uses the integer list provides
#                               as command arguments and evaluates the square 
#                               numbers of all of them. At the end of the 
#                               script the sum of all the squared numbers is 
#                               printed to the screen
#
#
#
#


# Error handling if the argument list is empty or contains string instead of integers.

if [ $# = 0 ]
then
        echo "Usage $0 -integer-list"
        exit 1
elif [ $@ = [^9-0] ]
then
        echo "No Strings are allowed."
fi

total=0
power=0

# Function used for summation of the squared number list.
sum()
{
        total=`expr $total + $power`    # Sum the total value.
}

# Iterates through the argument list.
for num in $@
do
        power=`expr $num \* $num`               # Evaluate the square for the current argument.
        echo "$num squared equals $power"       # Print to screen the square of the argument.
        sum             # Call the sum function to sum the square values togehter.      
done

# Prints the result of the sum function
echo "Total of squared numbers = $total"

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Athabasca University, Athabasca, Alberta, Canada, Prof. Mamoud Abaza, COMP325

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

GREP Command with several arguments

Hi! $ more file yoyo haha lili ... i want to test if a "grep yoyo AND lili" works in this file. In fact, my script will carry on only if it finds in the same line "yoyo" AND "lili" How can i do? Thx! (3 Replies)
Discussion started by: tomapam
3 Replies

2. UNIX for Dummies Questions & Answers

arguments in command line

Hi all, How many arguments can we pass while testing a prgm at command line.. I encountered an issue while passing 10 arguments. For $10 its taking argument passed for $1 followed by 'zero'. can we pass more than 9 arguments /Is there any other way. Thanks, rrs (6 Replies)
Discussion started by: rrs
6 Replies

3. HP-UX

get whole command arguments in ps -ef?

Hello All, I want to build some monitoring of processes in HP-UX 11.x. Is there any way to get the whole set of commands and arguments instead of the first 60 characters? I read that there's a limitation of the ps -ef command that we can't overcome. In this case is there any other command... (17 Replies)
Discussion started by: usfrog
17 Replies

4. Shell Programming and Scripting

how to filter `last` command for yesterday only

Hi Expert, May I know how to filter `last` command out put for yesterday only ? my `last` command out put: user1 pts/3 192.168.0.12 Wed Jun 25 03:58 still logged in user1 pts/3 192.168.0.33 Wed Jun 23 02:08 - 09:58 (00:49) user2 pts/1 192.168.0.21 ... (1 Reply)
Discussion started by: skully
1 Replies

5. UNIX for Dummies Questions & Answers

Command line arguments.

I am working on a script wherein i need the user to enter the Build ID for eg:the command line will show enter the build ID Now on entering the build ID it should be assigned to @ARGV. How can this be done.? (1 Reply)
Discussion started by: Varghese
1 Replies

6. Shell Programming and Scripting

filter grep command

I have ran into a small issue and I am not sure how to fix it. In one of our current scripts we have this line which does a grep to get the pid of the process. ps -ef | grep nco_p_syslog | grep $x | awk '{print $2}' However this is not returning anything due to the how long the value... (7 Replies)
Discussion started by: LRoberts
7 Replies

7. UNIX for Dummies Questions & Answers

command line arguments

hi, can someone how to accept command line arguments as a variable using in script? like: ./scriptname arguments by accept arguments, I can use it in my script? thx! (1 Reply)
Discussion started by: ikeQ
1 Replies

8. Homework & Coursework Questions

Using tail with the filter command

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Devise a chain of filters using some or all of the following programs pr, cut, cat, tail to display a numbered... (8 Replies)
Discussion started by: hbell221
8 Replies

9. Shell Programming and Scripting

Use of awk to filter out the command output

Hi All, I am trying to find out number of cores present for hp-ux server from the output of print_manifest (as shown below). i suppose awk will be best tool to use for filtering. output of print_manifest is : System Hardware Model: ia64 hp Integrity Virtual Partition ... (6 Replies)
Discussion started by: omkar.jadhav
6 Replies

10. Shell Programming and Scripting

Filter pattern in grep command

Hi, I am having a file like below hello how are you hello... (5 Replies)
Discussion started by: rohit_shinez
5 Replies
CREATE TEXT SEARCH 
DICTIONARY(7) SQL Commands CREATE TEXT SEARCH DICTIONARY(7) NAME
CREATE TEXT SEARCH DICTIONARY - define a new text search dictionary SYNOPSIS
CREATE TEXT SEARCH DICTIONARY name ( TEMPLATE = template [, option = value [, ... ]] ) DESCRIPTION
CREATE TEXT SEARCH DICTIONARY creates a new text search dictionary. A text search dictionary specifies a way of recognizing interesting or uninteresting words for searching. A dictionary depends on a text search template, which specifies the functions that actually perform the work. Typically the dictionary provides some options that control the detailed behavior of the template's functions. If a schema name is given then the text search dictionary is created in the specified schema. Otherwise it is created in the current schema. The user who defines a text search dictionary becomes its owner. Refer to in the documentation for further information. PARAMETERS
name The name of the text search dictionary to be created. The name can be schema-qualified. template The name of the text search template that will define the basic behavior of this dictionary. option The name of a template-specific option to be set for this dictionary. value The value to use for a template-specific option. If the value is not a simple identifier or number, it must be quoted (but you can always quote it, if you wish). The options can appear in any order. EXAMPLES
The following example command creates a Snowball-based dictionary with a nonstandard list of stop words. CREATE TEXT SEARCH DICTIONARY my_russian ( template = snowball, language = russian, stopwords = myrussian ); COMPATIBILITY
There is no CREATE TEXT SEARCH DICTIONARY statement in the SQL standard. SEE ALSO
ALTER TEXT SEARCH DICTIONARY [alter_text_search_dictionary(7)], DROP TEXT SEARCH DICTIONARY [drop_text_search_dictionary(7)] SQL - Language Statements 2010-05-14 CREATE TEXT SEARCH DICTIONARY(7)
All times are GMT -4. The time now is 06:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy