Solved

Command explanation (newbie).

Posted on 2002-07-29
11
217 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
  • 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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 50 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Debug VNC connection on CentOS7 server 22 87
Install Predefined Certificate on Ubunto 4 40
installing LSI MegaRAID Storage Manager on CentOS 7 22 363
error log using ftp 7 41
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
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.

803 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