Use of colon


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use of colon
# 1  
Old 09-09-2014
Use of colon

There was a sample code on forum I found sometime back:

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

$ f() { local foo; : ${foo=unset}; declare -p foo; }; f
declare -- foo="unset"

Can someone explain why was colon (:) is being used here. Whats its use?

Last edited by Don Cragun; 09-09-2014 at 05:45 PM.. Reason: Disable smilies in this posting.
# 2  
Old 09-09-2014
From the man page for the : command:
Code:
NAME
    colon - null utility
SYNOPSIS
    : [argument...]
DESCRIPTION
    This utility shall only expand command arguments. It is used when a command is needed, as in
    the then condition of an if command, but nothing is to be done by the command.

# 3  
Old 09-09-2014
Quote:
Originally Posted by Rameshck
Can someone explain why was colon (: ) is being used here.
Not really Smilie
Code:
$ help :
:: :
    Null command.
    
    No effect; the command does nothing.
    
    Exit Status:
    Always succeeds.
$

# 4  
Old 09-09-2014
Quote:
Originally Posted by junior-helper
Not really Smilie
Code:
$ help :
:: :
    Null command.
    
    No effect; the command does nothing.
    
    Exit Status:
    Always succeeds.
$

My thoughts too. It appears to do nothing special. I just began to wonder why they placed this option in shell. Thanks everyone.
# 5  
Old 09-09-2014
${foo=unset}, a conditional assignment, is run; the resulting value is discarded.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to print string after colon?

Hi How do I print character after colon":" below is input file BUC1 : 33157147, BUC1 COUNT : 478455,BUC1 : 9930334.18 BUC2 : 1203100,BUC2 COUNT : 318678,BUC2 GIVEN : 3493491.59 BUC3 : 234567.99 expected output 33157147 478455 9930334.18 12031002 318678 3493491.59 234567.99 (10 Replies)
Discussion started by: scriptor
10 Replies

2. Shell Programming and Scripting

Print after colon

I have entries like below in a file 11.22.33.44:80 22.33.44.55:81 :::587 :::465 What I need is to take out the part after colon ( : ) Output should be as follows. 80 81 587 465 I used cut -d: -f 2 but its not working as dedired. (2 Replies)
Discussion started by: anil510
2 Replies

3. Shell Programming and Scripting

How to replace colon in HH:MI:SS to hypen?

I have a file that contains timestamp in some of the rows in the file and the field separator is colon and some of the rows have numerical values, timestamp and characters with colon as the field separator We are looking to change colon in HH:MI:SS for the timestamp to hyphen “-“ leaving the field... (1 Reply)
Discussion started by: cumeh1624
1 Replies

4. Shell Programming and Scripting

Bash, remove numbers after colon

Hello All, I was wondering if someone might know how to do this. I have a word list that is format like the example below. I need to take away the :number after that... is there some kind of command I could use to remove them? 123456:5562 password:1507 123456789:989 qwerty:877... (7 Replies)
Discussion started by: 3therk1ll
7 Replies

5. Shell Programming and Scripting

Sort numbers which has colon (:) in between

Although i tried multiple option i couldn't find a way to get the rigt ouput. Say i have the following data cat file.txt C request C response C request C response The output should look like (9 Replies)
Discussion started by: varu0612
9 Replies

6. Shell Programming and Scripting

Colon in awk script output

I'm using AIX 5.3 and running a awk replace to modify data as follows: echo 1234: 1234 123 123 444 555 666 7777 | awk '/^:/{split($2,N);n=N} {n=$1} {sub(n,n+10000000)}1' 10001234 1234 123 123 444 555 666 7777 dumb question.. how do I get the colon back in, so it outputs 10001234: 1234... (4 Replies)
Discussion started by: say170
4 Replies

7. UNIX for Dummies Questions & Answers

Why do we use a colon (:) in grep?

Can some one please explain why do we use colon in a grep statement . for eg: ORACLE_SID=$(grep :$(echo $JOBNAME |cut -c1-3): ${SWENV_TAB}|awk -F: '{print $1}') Thanks in advance Sri (5 Replies)
Discussion started by: Sri3001
5 Replies

8. Shell Programming and Scripting

Remove char after Colon

Hi guys, This is my input 2735:<7001> 34 789 701 2 2774:<7001> 34 789 701 2 How to delete characters after colon : Including colon : too ? My output should... (3 Replies)
Discussion started by: gowrishankar05
3 Replies

9. Solaris

how to delimit a colon

I want to know how to delimit a colon in a file name while scp ing from one host to other host. I used forward slash(\) but that is not working. (1 Reply)
Discussion started by: rogerben
1 Replies

10. Shell Programming and Scripting

two lines into one colon separated line...

Does anyone know how to get these two output lines into one colon ':' separated line with some unix command? Maybe nawk. I've tried to read the nawk and awk man pages but I don't get it right. Are these commands the one to use? Output from find command: # /sw/tools/matlab/7.0.1/man... (2 Replies)
Discussion started by: tonlu
2 Replies
Login or Register to Ask a Question