I'm running into a very weird situation. Let's forget about the purpose of my initial script please. I noticed the bug whatever I'm trying to do.
I'm on an old server running bash 3.1.17.
Say we have the following script :
When I execute it, I get the following result:
Meaning that the command "local" makes the variable be set even if no value was given to it. This is not the behavior I've seen on any other server.
Can anyone explain what's going on?
Thanks
Santiago
---------- Post updated at 00:39 ---------- Previous update was at 00:19 ----------
I tested my little script on several servers and got the following results :
Is this a bug of bash-3.x?
Am I not expecting the right behavior from "local" command?
Thanks for your help
Santiago
Last edited by Franklin52; 11-23-2015 at 10:47 AM..
Reason: Adding code tags
Apparently this is a difference between bash-3 and bash-4.
(I reproduced the old behavior with bash-3.2.57 and the new behavior with bash-4.1.)
You are right, local var without a value should be a declaration as in bash-4, rather than a definition as in bash-3.
I'm used to use local in all my bash functions just to make sure I'm not messing with variables from the parent script. My workaround to make scripts compatible with bash-3 and bash-4 is :
Do you see any better idea?
Thx
This User Gave Thanks to chebarbudo For This Post:
Thanks MadeInGermany, I know :+ and :- very well.
In my particular case, I actually need to know if a var is set. Example: In a function, I need to parse an argument and at the same time tell if it matches a regular expression.
Of course this is a bare simple example and it's not accurate. But it tells you my original purpose. In the case of bash-3.x, the script fails if you remove the unset command.
How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address
and column 3 contains “cc” e-mail address to include with same email.
Sample input file, email.txt
Below is an sample code where... (2 Replies)
This really puzzles me. The following code gives me the error 'expr: syntax error' when I try to do multi-line comment using here document
<<EOF
echo "Sum is: `expr $1 + $2`"
EOF
Even if I explicitly comment out the line containing the expr using "#", the error message would still exist... (3 Replies)
Hi,
I'm trying to sort a text file "test":
S12
S_S12
S_S1_12
S15
S_N15
S_N1_15
By "sort test", I get:
S12
S15
S_N1_15
S_N15
S_S1_12
S_S12
It seems weird:
Comparing Line 2 and Line 3, it must be that '-' is bigger than '1'; however, comparing Line 3 and Line 4, it seems that... (3 Replies)
I've posted about this before, but only recently narrowed the problem down to a specific cause.
Ok, first of all, the behavior:
It occurs when autocompletion brings up its list (not when there is only a single option). Basically, if I were to type, say,
cd ~/<TAB>
I would get something... (2 Replies)
I am trying to find lines in a text file larger than 3 Gb that start with a given string. My command looks like this:
$ look "string" "/home/patrick/filename.txt"
However, this gives me the following message:
"look: /home/patrick/filename.txt: File too large"
So, I have two... (14 Replies)
Hi,
I have line in input file as below:
3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL
My expected output for line in the file must be :
"1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL"
Can someone... (7 Replies)
Is it normal behavior for a shell script that terminates to terminate its parent shell when executed with the "." option?
For example, if I have the example script (we'll name it ex.sh):
#!/bin/sh
if
then
echo "Bye."
exit 2
fi
And I execute it like this:
>./ex.sh
It... (6 Replies)