, you have the logical error that the "command substitution" will replace the function with its output to stdout while the (exit) code conveyed by the return command can be retrieved in the $? parameter.
, you have the logical error that the "command substitution" will replace the function with its output to stdout while the (exit) code conveyed by the return command can be retrieved in the $? parameter.
Thanks so much, and just so I understand your quote above. Does this mean that the $zone value I'm returning from the function set_region will just be wiped out everytime?
Also does this look better for the if statement, I'm not sure if || means or, because I'm only looking for those numbers? ---------- Post updated at 04:01 PM ---------- Previous update was at 03:31 PM ----------
Now it just hangs and throws the same error when you hit enter.
Using comments might be easier for me to explain what I'm trying to do:
#A function to call another function to get a user to enter a valid region in a variable
#Use that variable in another command
#Print out the results from the command
#A function for getting the users region and making sure it's in a valid list
#Request the user input a region and get it in a variable
#A while loop that keep going as long as the user input doesn't match a valid region
#A for loop to test the user input against the valid regions
#Matching with a valid region exit the while loop
#Not matching rerun through the while loop
#Return the zone that was found to be valid
Saying you're getting an error when you hit return without showing us the exact error you are getting wastes all of our time and delays getting help from us. But, in this case it is obvious that you still have the syntax errors in the tests in your if statement, ksh (and any other shell conforming to the standards) requires whitespace separating all of the arguments in a test command (AKA [expression] command), and the numeric equal comparison operator in that expression is -eq; not eq. This might come closer to what you're trying to do, but without seeing how you are calling the functions you're talking about and seeing how you're testing the results produced by this code segment, we don't know whether or not it will do what you need:
or with more readable lines:
and, for something with this many tests, a case statement might be a better choice than an if statement.
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)
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)
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)
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)
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)
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)
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)
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)