Computing.Net > Forums > Linux > hello two questions about unix scripts

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

hello two questions about unix scripts

Reply to Message Icon

Name: theking2725
Date: May 11, 2009 at 14:42:59 Pacific
OS: Windows XP
Subcategory: General
Comment:

hello , my first question is
i) i have made a new script in this script i have a variable called found , in this script i call a subscript and i want that this subscript change the value of my variable if needed, i tried to export it but without effort do anyone have an idea

ii)again i am calling the same script with some argument in the script i want to store the number of arguments in a variable called number , how can i do this



Sponsored Link
Ads by Google

Response Number 1
Name: theking2725
Date: May 11, 2009 at 16:40:27 Pacific
Reply:

well i have tried to solve the following
number= $* | wc -w but it has give error how to do it help people


0

Response Number 2
Name: nails
Date: May 11, 2009 at 21:07:34 Pacific
Reply:

i) I'm not sure from your description, but I think you are trying to capture the output of another shell script. You normally use command substitution to capture the output of a command.

Assume your shell script named subscript is in the same directory and contains this one line:

echo "helloworld"

Now, in your main script, using korn or bash shell, execute subscript within $():

#!/bin/bash

found=$(./subscript)
echo "$found" # should be helloworld

# the older bourne shell uses backtics for command substitution:

found=`./subscript`
echo "$found"

ii) the $# variable contains the number command line arguments

echo "number of args: $#"


0

Response Number 3
Name: theking2725
Date: May 12, 2009 at 02:03:10 Pacific
Reply:

hi nails i am very proud of your answers but i think i asked the question in a wrong manner, for the first question i am writing a sort algorithm i get each line of the text one by one and i send the line as argument to the subscript , and i have a variable called found in the main script, the subscripts checks whethe a keyword matches with any word in the line which is send as an argument to the subscript, i want, if there is a match between a word in the line and the keyword, found to increase one, if no match then it will stay unchanged, and the end when all lines checked , i want found to contain number of matches, so while i tried the found has not changed when i use export option it makes the variable read only, so that is the first question

ii) the second one i hope i solved i just want the output of the echo which is a number in my case i.e. i make echo $x + $y (or any expression) to be stored in a variable called $number so that i can make arithmetical operations on it, for this purpose i found that
number= ' echo ls | wc -w '
i tried it worked it assigns the output of the wc command to the variable number, if anyone knows any shortcut method better than i would like to know


0

Response Number 4
Name: David Perry
Date: June 2, 2009 at 10:47:46 Pacific
Reply:

use the backtick ( under the tilde key ) instead of single quotes.

number=`ls | wc -w`


0

Response Number 5
Name: katenlee
Date: August 19, 2009 at 17:24:21 Pacific
Reply:


Thanks for your sharing. Thanks for sharing this useful information. It's great.


[url=http://sonneriegratuite.org/][color=#FFFFFF][u]gratuit pour mobile sonnerie portable mp3[/u][/color][/url][color=#FFFFFF] - Sonnerie portable MP3 est en effet un pouvoir de l'innovation technologique. Êtes-vous familier avec cette sonnerie portable?[/color][url=http://sonneriegratuite.org/][color=#FFFFFF][u]gratuit pour mobile sonnerie portable mp3[/u][/color][/url]


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: hello two questions about unix scripts

Question about linux kernel www.computing.net/answers/linux/question-about-linux-kernel/16906.html

UNIX Script help www.computing.net/answers/linux/unix-script-help/7820.html

Some questions about the kernel www.computing.net/answers/linux/some-questions-about-the-kernel/2797.html