Assignment operator without operand


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Assignment operator without operand
# 1  
Old 08-22-2014
Assignment operator without operand

Does anyone know how this line in bash works?

Code:
local gotbase= force= nicelevel corelimit
local pid base= user= nice= bg= pid_file=
local cgroup=

These lines are part of the daemon function inside the "functions" file at /etc/init.d in RH.

Last edited by Don Cragun; 08-22-2014 at 06:06 PM.. Reason: Change bold tags to CODE tags, add missing ICODE tags.
# 2  
Old 08-22-2014
All of the variables listed are tagged as "local"; gotbase, force, base, user, nice, pid_file, and cgroup are explicitly initialized to empty strings.
# 3  
Old 08-22-2014
Most tests check for unset or null values.

Code:
mute@thedoctor:~$ f() { local foo; [[ $foo ]] || echo empty; }; f
empty
mute@thedoctor:~$ f() { local foo=; [[ $foo ]] || echo empty; }; f
empty

But you'll see a difference with something like this:

Code:
mute@thedoctor:~$ f() { local foo=; : ${foo=unset}; declare -p foo; }; f
declare -- foo=""
mute@thedoctor:~$ f() { local foo; : ${foo=unset}; declare -p foo; }; f
declare -- foo="unset"

This User Gave Thanks to neutronscott For This Post:
# 4  
Old 08-22-2014
Quote:
Originally Posted by Don Cragun
All of the variables listed are tagged as "local"; gotbase, force, base, user, nice, pid_file, and cgroup are explicitly initialized to empty strings.
Thanks Don. SmilieSmilie

---------- Post updated at 03:27 PM ---------- Previous update was at 03:16 PM ----------

Quote:
Originally Posted by neutronscott
Most tests check for unset or null values.

Code:
mute@thedoctor:~$ f() { local foo; [[ $foo ]] || echo empty; }; f
empty
mute@thedoctor:~$ f() { local foo=; [[ $foo ]] || echo empty; }; f
empty

But you'll see a difference with something like this:

Code:
mute@thedoctor:~$ f() { local foo=; : ${foo=unset}; declare -p foo; }; f
declare -- foo=""
mute@thedoctor:~$ f() { local foo; : ${foo=unset}; declare -p foo; }; f
declare -- foo="unset"

Thanks neutronscott,
Looks like they had a reason for explicitly declaring them and setting them to empty strings.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Newbie question: modulo operator with negative operand, bug or feature?

Hi, I'm new to the Ash shell so my apologies if this is well known. In normal maths and other shells and languages I've used, the modulo operator always returns a positive remainder. For example see this discussion (first post so I can't hyperlink it): ... (11 Replies)
Discussion started by: FleetFoot
11 Replies

2. Programming

Need to understand the overloaded assignment operator behavior

Hi, In the following code, class A { public: void operator=(const A& rhs) { if (this == &rhs) cout << "self-assigned"; } }; class B { A a; // should not be a pointer member, (i.e) A* a }; int main() { B b; b = b; // Ans: self-assigned } I am really... (5 Replies)
Discussion started by: royalibrahim
5 Replies

3. Homework & Coursework Questions

Compiler error "lvalue required as left operand of assignment"

1. After trying to compile code error is given Lvalue required as left operand of assignment. 2. Relevant commands, code, scripts, algorithms: if , else if 3. The attempts at a solution (include all code and scripts): /* File: incircles.cpp Created by: James Selhorst ... (2 Replies)
Discussion started by: c++newb
2 Replies

4. Programming

"lvalue required as left operand of assignment" error in C

Hey all. I've been working on some fun with C and decided to write a Rock Paper Scissors game. The problem is, that when I try to compile the file, it gives "lvalue required as left operand of assignment" error. The error line is here: for ((point1=0 && point2=0); ((point1=3) || (point2=3));... (4 Replies)
Discussion started by: drouzzin
4 Replies

5. Programming

lvalue required as left operand of assignment

z < 0 ? z= z + 2*r*cos(theta) : z= z - 2*r*cos(theta); Does anyone know what is wrong here? I've got compiler msg: lvalue required as left operand of assignment All variables are "double". I'm using gcc compiler (but I don't think that matters) (5 Replies)
Discussion started by: EmilyTheStrange
5 Replies

6. Programming

c++ assignment operator overloading

Hello everyone! Suppose that I have something like this A a; a.mem=new int; A b = a; where class A { public: int * mem; A() : mem(NULL) { } ~A() { if (mem!=NULL) delete mem; (1 Reply)
Discussion started by: bashuser2
1 Replies

7. Programming

Need help compiling in C: lvalue required as left operand of assignment

Hi, I am trying to compile a program (not coded by me), and i'm getting this error: 203: error: lvalue required as left operand of assignment As you may be guessing, the program doesn't compile, the line number 203 is the following: ... (2 Replies)
Discussion started by: Zykl0n-B
2 Replies

8. Shell Programming and Scripting

syntax error: `-a' unexpected operator/operand in IF

When i tyr this, it gives me a syntax error...i tried removing quotes,removing spaces,replacing -eq with '='.. Can somebody suggest that is the problem? if ]; then (4 Replies)
Discussion started by: dba.admin2008
4 Replies

9. Shell Programming and Scripting

scalar variable assignment in perl + { operator

When reading over some perl code in a software document, I came across an assignment statement like this $PATH = ${PROJECT}/......./.... In this particular form of scalar variable assignment, what does the curly braces operators do ? Also, what is the benefit in doing scalar assignment this... (3 Replies)
Discussion started by: JamesGoh
3 Replies

10. Programming

what is diff b/w copy constructor and overloaded assignment operator

Helo i m new in c++. i m confuse about what is exact difference b/w copy constructor and overloaded assignment operator. Regards, Amit (3 Replies)
Discussion started by: amitpansuria
3 Replies
Login or Register to Ask a Question