Sponsored Content
Full Discussion: Function Returns
Top Forums Shell Programming and Scripting Function Returns Post 302979323 by akechnie on Friday 12th of August 2016 09:50:41 AM
Old 08-12-2016
Function Returns

I'm having a little trouble returning a value from a function or calling it, I'm not quite sure.

I'm calling the function here
Code:
function region_lookup_with_details {
        results = $(set_region)
        echo $results
}

This is the function I'm calling
Code:
function set_region {
        zonecheck eq 0
        while $zonecheck eq 0
        do
                echo "Please enter the region you want to use\n"
                read zone
                if $zone eq 4 || $zone eq 5 || $zone eq 6 || $zone eq 7  || $zone eq 10 || $zone eq 11 || $zone eq 20 || $zone eq 21  || $zone eq 23 || $zone eq 25
                then
                        $zonecheck eq 1
                else
                        echo "That's not a region\n"
                fi
        done
        return $zone
}

This is the error I'm getting
Code:
./test[150]: region_lookup_with_details[57]:set_region[15]:2: not found [No such file or directory]


Last edited by rbatte1; 08-12-2016 at 11:13 AM.. Reason: Added CODE tags for final output
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

function returns string

Can I create a function to return non-interger value in shell script? for example, function getcommand () { echo "read command" read command echo $command } command=$(getcommand) I tried to do something as above. The statement echo "read command" does not show up. ... (5 Replies)
Discussion started by: lalelle
5 Replies

2. UNIX for Dummies Questions & Answers

Grep without returns...

Is there a command where I can pipe my grep into it and it will output it with spaces rather than returns? Example I want to turn prompt$ grep blah file blah blah into this prompt$ grep blah file | someCommand blah blah (1 Reply)
Discussion started by: mrwatkin
1 Replies

3. Shell Programming and Scripting

Function returns wrong values - solved

Hi I have a small function which returns a wrong value. The function tries to make a connection to oracle database and tries to get the open_mode of the database in the variable status. However when a database is down the value of the status column is set to READWRITE i am not sure why. I... (0 Replies)
Discussion started by: xiamin
0 Replies

4. Shell Programming and Scripting

Grep returns nothing

Hi all, I am trying to grep a .txt file for a word. When I hit enter, it returns back to $ The file is 4155402 in size and is named in this way: *_eveningtimes_done_log.txt I use this command, being in the same directory as the file: grep -i "invalid" *_eveningtimes_done_log.txt ... (16 Replies)
Discussion started by: DallasT
16 Replies

5. UNIX for Dummies Questions & Answers

dlsym() returns 0 for an existing function

Sometimes I observe this in gdb: (gdb) br my_function Breakpoint .. at 0x...: file ..., line ... i.e., "my_function" does exist in the current executable. however, dlsym does not find it: (gdb) p dlsym(0,"my_function") $6 = 0 This is a C program; dlsym does find other defined functions and... (2 Replies)
Discussion started by: sds
2 Replies

6. Shell Programming and Scripting

Calculation returns no value

#/bin/sh ..... #convert memory to MB let "mmsize_a= ($mmsize)/256" let "mminuse_a= ($mminuse)/256" let "mmfree_a= ($mmsize_a -$mminuse_a)" let "mmfreepercent= (($mmfree_a)/($mmsize_a))*100" # #format output echo "\n\n######################" >>$sndFile echo "\n$sysName Total Memory usage"... (3 Replies)
Discussion started by: Daniel Gate
3 Replies

7. Shell Programming and Scripting

Function returns a value but cannot be stored in other variable

I need help to store the value returned from the function to one variable and then use that variable. PREVIOUS_DATE_FUNCTION() { date '+%m %d %Y' | { read MONTH DAY YEAR DAY=`expr "$DAY" - 1` case "$DAY" in 0) MONTH=`expr "$MONTH" - 1` case... (1 Reply)
Discussion started by: aroragaurav.84
1 Replies

8. Shell Programming and Scripting

Help in function returns value

Hi, I need to return a value from the function. the value will be the output from cat command which uses random fucntion. #!/bin/ksh hello() { var1=$(`cat /dev/urandom| tr -dc 'a-zA-Z0-9-!%&()*+,-/:;<=>?_'|fold -w 10 | head -n 1`) echo "value is" var1 return var1 } hello var=$?... (2 Replies)
Discussion started by: Nandy
2 Replies

9. Shell Programming and Scripting

Exit always returns 0

This returns 0 even when it does not delete any files. Is it because -print returns 0? RETVAL=$? Docs_Backups=/media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/Documents_Backups/ Scripts_Backups=/media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/Script_Backups/ # create some old files #touch -d 20120101... (4 Replies)
Discussion started by: drew77
4 Replies
getzoneid(3C)                                              Standard C Library Functions                                              getzoneid(3C)

NAME
getzoneid, getzoneidbyname, getzonenamebyid - map between zone id and name SYNOPSIS
#include <zone.h> zoneid_t getzoneid(void); zoneid_t getzoneidbyname(const char *name); ssize_t getzonenamebyid(zoneid_t id, char *buf, size_t buflen); DESCRIPTION
The getzoneid() function returns the zone ID of the calling process. The getzoneidbyname() function returns the zone ID corresponding to the named zone, if that zone is currently active. If name is NULL, the function returns the zone ID of the calling process. The getzonenamebyid() function stores the name of the zone with ID specified by id in the location specified by buf. The bufsize argument specifies the size in bytes of the buffer. If the buffer is too small to hold the complete null-terminated name, the first bufsize bytes of the name are stored in the buffer. A buffer of size {ZONENAME_MAX} is sufficient to hold any zone name. If buf is NULL or bufsize is 0, the name is not copied into the buffer. RETURN VALUES
On successful completion, getzoneid() and getzoneidbyname() return a non-negative zone ID. Otherwise, getzoneidbyname() returns -1 and sets errno to indicate the error. On successful completion, the getzonenamebyid() function returns the buffer size required to hold the full null-terminated name. Otherwise, it returns -1 and sets errno to indicate the error. ERRORS
The getzoneidbyname() function will fail if: EFAULT The name argument is non-null and points to an illegal address. EINVAL A zone with the indicated name is not active. ENAMETOOLONG The length of the name argument exceeds {ZONENAME_MAX}. The getzonenamebyid() function will fail if: EINVAL A zone with the specified ID is not active. EFAULT The buf argument points to an illegal address. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ SEE ALSO
intro(2), chroot(2), malloc(3C), attributes(5), zones(5) SunOS 5.10 1 Nov 2004 getzoneid(3C)
All times are GMT -4. The time now is 06:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy