Solved

Command explanation (newbie).

Posted on 2002-07-29
11
216 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
 
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
add a 1000 ms delay after each sending email operation 12 70
Java / Linux and Regular Expressions 11 71
LINUX CENTOS + APACHE 9 63
Access_log 17 100
Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now