How to return a string?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to return a string?
# 1  
Old 10-28-2010
How to return a string?

Code:
function blah {
return "string"
}

it keeps saying string: not found

How can i do this guys? Because I'm trying to do something like this

Code:
function print_daemon_options {
	echo "Start Daemons - Please enter one or a combination of the following:"
	
	if isDatasubEnabled && isReconEnabled; then
		echo "1 = CGT, 2 = Subscriber, 3 = Order Monitor, 4 = Revaluations, 5 = Reconciliation, 6 = All, 7 = Exit"
		allowedInput = "1 2 3 4 5 6 7"
	
	elif isDatasubEnabled && isReconEnabled=0; then
		echo "1 = CGT, 2 = Subscriber, 3 = Order Monitor, 4 = Revaluations, 6 = All, 7 = Exit"
		allowedInput = "1 2 3 4 6 7"

	elif isDatasubEnabled=0 && isReconEnabled; then
		echo "1 = CGT, 3 = Order Monitor, 4 = Revaluations, 5 = Reconciliation, 6 = All, 7 = Exit"
		allowedInput = "1 3 4 5 6 7"
		
	else
		echo "1 = CGT, 3 = Order Monitor, 4 = Revaluations, 6 = All, 7 = Exit"
		allowedInput = "1 3 4 6 7"
	fi
	
	return $allowedInput
}

# 2  
Old 10-28-2010
Try:
Code:
function blah {
  echo "string"
}

# 3  
Old 10-28-2010
Functions return numbers (return codes).

echo the string, or set it in a variable.

i.e.
Code:
blah() {
  _RC="string"
}

blah
echo $_RC

Code:
blah() {
  echo string
}

_RC=$(blah)

# 4  
Old 10-28-2010
Thanks for the reply Scott. I've got a function like this

Code:
function print_daemon_options {
    echo "Start Daemons - Please enter one or a combination of the following:"
    
    if isDatasubEnabled && isReconEnabled; then
        echo "1 = CGT, 2 = Subscriber, 3 = Order Monitor, 4 = Revaluations, 5 = Reconciliation, 6 = All, 7 = Exit"
        allowedInput = "1 2 3 4 5 6 7"
    
    elif isDatasubEnabled && isReconEnabled=0; then
        echo "1 = CGT, 2 = Subscriber, 3 = Order Monitor, 4 = Revaluations, 6 = All, 7 = Exit"
        allowedInput = "1 2 3 4 6 7"

    elif isDatasubEnabled=0 && isReconEnabled; then
        echo "1 = CGT, 3 = Order Monitor, 4 = Revaluations, 5 = Reconciliation, 6 = All, 7 = Exit"
        allowedInput = "1 3 4 5 6 7"
        
    else
        echo "1 = CGT, 3 = Order Monitor, 4 = Revaluations, 6 = All, 7 = Exit"
        allowedInput = "1 3 4 6 7"
    fi
    
    echo allowedInput
}


function stop_daemons {
    print_daemon_options

    echo $allowedInput
}

stop_daemons calls the print one which should echo the options and also return the string but the error I get is:

Start Daemons - Please enter one or a combination of the following:
1 = CGT, 2 = Subscriber, 3 = Order Monitor, 4 = Revaluations, 5 = Reconciliation, 6 = All, 7 = Exit
print_daemon_options: ./wmfo_menu.sh[383]: allowedInput: not found
allowedInput
# 5  
Old 10-28-2010
You need to remove the spaces from your variable assignments:

Code:
allowedInput="......"

I presume all of the isDatasubEnabled etc., are external programs?
# 6  
Old 10-28-2010
I made the change and I still get an error (and also, yep isDatasubEnabled and isReconEnabled are functions within the same script)

Code:
function print_daemon_options {
    echo "Start Daemons - Please enter one or a combination of the following:"
    
    if isDatasubEnabled && isReconEnabled; then
        echo "1 = CGT, 2 = Subscriber, 3 = Order Monitor, 4 = Revaluations, 5 = Reconciliation, 6 = All, 7 = Exit"
        allowedInput="1 2 3 4 5 6 7"
    
    elif isDatasubEnabled && isReconEnabled=0; then
        echo "1 = CGT, 2 = Subscriber, 3 = Order Monitor, 4 = Revaluations, 6 = All, 7 = Exit"
        allowedInput="1 2 3 4 6 7"

    elif isDatasubEnabled=0 && isReconEnabled; then
        echo "1 = CGT, 3 = Order Monitor, 4 = Revaluations, 5 = Reconciliation, 6 = All, 7 = Exit"
        allowedInput="1 3 4 5 6 7"
        
    else
        echo "1 = CGT, 3 = Order Monitor, 4 = Revaluations, 6 = All, 7 = Exit"
        allowedInput="1 3 4 6 7"
    fi
    
    echo $allowedInput
}


function stop_daemons {
    print_daemon_options

    echo $(allowedInput)
}

Start Daemons - Please enter one or a combination of the following:
1 = CGT, 2 = Subscriber, 3 = Order Monitor, 4 = Revaluations, 5 = Reconciliation, 6 = All, 7 = Exit
1 2 3 4 5 6 7
stop_daemons: ./wmfo_menu.sh[383]: allowedInput: not found
# 7  
Old 10-28-2010
If this is the culprit
Code:
function stop_daemons {
    print_daemon_options

    echo $(allowedInput)
}
# then change to echo ${allowedInput}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

How to pass int and return string in C?

hi I want to write a function which takes int as input and returns a string like this. char GetString(int iNo) { switch(iNo) { case 0: return "Zero"; break; case 1: return "One"; break; } } void main() { int i; printf("Enter... (1 Reply)
Discussion started by: atharalikhan
1 Replies

2. Shell Programming and Scripting

return part of a string in bash

Hi, I would like to return the last part of a string in an array of strings in bash. The array contains in each position the content below: and I would like to return only the last part of each string. The correct result would be: How can I do that in bash using AWK?... (7 Replies)
Discussion started by: anishkumarv
7 Replies

3. UNIX for Dummies Questions & Answers

search for string and return substring

Hi, I have a file with the following contents: I need to create a script or search command that will search for this string 'ENDC' in the file. This string is unique and only occurs in one record. Once it finds the string, I would like it to return positions 101-109 ( this is the date of... (0 Replies)
Discussion started by: Lenora2009
0 Replies

4. UNIX for Dummies Questions & Answers

Search for string and return lines above and below

Hi, I have a file with the following contents: COMPANY ABCD TRUCKER JOE SMITH TRUCK 456 PLATE A12345678 TRUCKER BILL JONES TRUCK 789 PLATE B7894561 I need to create a script or search command that will search for this string '789' in the file. This string is unique and only... (7 Replies)
Discussion started by: doza22
7 Replies

5. Shell Programming and Scripting

Search string and return only the 5th line

I have looked at almost every posting on here regarding, grep, sed, awk, nawk, perl methods to perform this function, but they are just not returning the results I hope to see. Example File: abcdef 123456 ghijkl 7890123 7890123 7890123 7890123 mnopqrs 456789 This is the most... (4 Replies)
Discussion started by: doza22
4 Replies

6. Shell Programming and Scripting

KSH Functions String return

Hy everybody I'm trying to write a function like function(){ final=$1 return $final } but I get following error: "return: bad non-numeric arg ''" what shall I do? Isn't it possible to return strings?:confused: thanks lucae (2 Replies)
Discussion started by: lucae
2 Replies

7. Shell Programming and Scripting

return string in functions

Hi friends I need to return string value in functions can anyone help me out to return string values rather than integer. #!/bin/bash add_a_user() { USER=$1 COMPANY=$2 shift; shift; echo "Adding user $USER ..." echo "$USER working in $COMPANY ..." ret_type=YES return... (1 Reply)
Discussion started by: kittusri9
1 Replies

8. Shell Programming and Scripting

deleting 'carriage return' from string

hi there I'm getting a string from a sqlplus query, and I need to compare it with another string Problem here, is that the string i get from query brings a 'carriage return' with it, and comparing throws always false value. i need to delete all carriage retun charactres in string. how... (6 Replies)
Discussion started by: viko
6 Replies

9. Shell Programming and Scripting

String search and return value from column

Dear All I had below mention file as my input file. 87980457 Jan 12 2008 2:00AM 1 60 BSC1 81164713 Jan 12 2008 3:00AM 1 60 BSC2 78084521 Jan 12 2008 4:00AM 1 60 BSC3 68385193... (3 Replies)
Discussion started by: jaydeep_sadaria
3 Replies

10. Shell Programming and Scripting

return line below string grepp'ed for

Hi there Does anybody know how to get grep to return the line underneath the string i am grepping for ie, if i have this file hello everybody how are you and i issue #cat file | grep how I would like it to return the line below (in this case the string "are") Is this... (2 Replies)
Discussion started by: hcclnoodles
2 Replies
Login or Register to Ask a Question