?
Solved

Command explanation (newbie).

Posted on 2002-07-29
11
Medium Priority
?
223 Views
Last Modified: 2010-04-20
Hi,

Can someone please explain this Korn shell command?

: ${test:="/test"}

The thing that's throwing my for a loop is that first ":".  I don't understand that.

Any assistance would greatly be appreciated.

Thanks
0
Comment
Question by:davism
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7186495
: is the null command (no-op) in ksh
about the the parameter substitution: stolen from man ksh:

${name:=word}
       if name is set and not  null,  it  is  substituted,
       otherwise  it  is  assigned  word and the resulting
       value of name is substituted.
0
 
LVL 1

Author Comment

by:davism
ID: 7186539
But what does the null command mean?  Is it's a true null value then why have it there?  Does it do anything?  If it was absent would it change anything
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7186547
it does nothing, you can remove it (in sh, ksh, csh, tcsh, but not bash)
some programmers just use it like a comment (#)
0
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 1

Author Comment

by:davism
ID: 7186558
What does it do in bash?

Also, does it actually do anything to any commands on the same line if it has a ":"?  So, for instance, in the command:

: ${test:="/test"}

In a ksh, with the ":" being there does the remainder of the line (i.e. ${test:="/test"}) actually do anything or it the entire line treated like a comment?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7187301
as I said:
  the : command is a no-op (no operation), it does nothing, it does not execute anything, it is a "write-only" command, the shell will not do anything with it, the shell will ignore the complete line
DO YOU NEED MORE EXPLANATIONS?

That's different in bash (unfortunately), 'cause bash evaluates anything in the line before it realizes that it is a no-op.
0
 
LVL 1

Author Comment

by:davism
ID: 7188010
Yes, I would like a more detailed explanation.

In fact, from what I'm seeing IT DOES DO something.

: ${test:="/test"}

will still assign the literal "/test", IF $TEST is NOT ALREADY defined. And yes, I understand you had already mentioned that but this is the ":" comes in.  Without the ":", I would have a command like:

${test}:="/TEST"

I end up with:

/test: not found

With the ":", where I could have the command:
: ${test:="/test"}

Assuming the variable test, is not already defined then I end up with test being equal to "/test".

If it doesn't execute anything after the ":" (so in essence, a comment equivalent) then how is $test being equal to "/test"?  

Or is this what you are talking about with reference to bash shell?

Not trying to be a pain or argumentative, just looking for consise explanations to what I'm seeing (when I tried) it and what I'm hearing and reading.  I must be missing something here somewhere and I'm just trying to find out what that is. :-)
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7188135
damn, checked Linux and its (pd)ksh man-pages where the : command is mentioned for the POSIX mode only.

From AT&T ksh man-page:

...
: [ arg ... ]
          The command only expands parameters.
...

so it does exactly what you described. It's a no-op, for any shell command but expands parameters.
Sorry for confusion.
0
 
LVL 1

Author Comment

by:davism
ID: 7188171
Terminology thing, I think, but when it says "expands parameters" isn't it actually executing the parameters where the parameter is a command or command substitution?

From what I'm gathering, it seems more like an execution but if the ":" is there it forcibly returns a success status (0 status) or a NULL execution (implying a success?)and that's why there is no message being displayed (i.e. it treats it as a successful command REGARDLESS)

Would that be a correct assessment?  If not, can you explain in "general" terms (remember, I'm a "newbie" when it comes to Unix) or any materials/books that you can recommend that can explain it in "general" terms with examples?

(haha...all this for a STUPID ":"...haha.)
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 200 total points
ID: 7188204
> .. "expands parameters" isn't it actually executing the parameters ..
no.
parameters can be expanded, commands are executed

And yes, : always returns 0

> .. it treats it as a successful command ..
yes the : command (not the parameter expansion)

> .. correct assessment?
my english is to weak for such philosophical/pedantic/theoretical discussions ;-)
Sorry, don't have a referece handy.
0
 
LVL 1

Author Comment

by:davism
ID: 7188371
Great, thanks for that clarification it does make more sense, now. :-)  

Really appreciate the info and the time spent going over this...haha, again, all over a stupid ":".

Thanks again. :-)
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7188384
even stupid questions get answered ;-)
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month12 days, 10 hours left to enroll

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question