Computer Hope

Software => BSD, Linux, and Unix => Topic started by: madhavi on June 11, 2004, 07:43:30 AM

Title: why is the command "chomp" used in UNIX
Post by: madhavi on June 11, 2004, 07:43:30 AM
hi everybody,
can u tell what is the use of the command "chomp" in UNIX?
and even can i know what is the use of @ inUNIX?
Title: Re: why is the command "chomp" used in U
Post by: Joleen on June 25, 2004, 01:16:57 PM
I believe chomp has something to do with removing trailing spaces from a string.. er maybe I'm thinking of C programming.
Title: Re: why is the command "chomp" used in U
Post by: googler on July 21, 2004, 01:48:54 PM
You are partially right.
It is used in perl programming as a way to remove a new line.
Heres toy code:

#!/usr/bin/perl -w

my $s = "Chomping..\n";
print $s; #print with new line
chomp ($s); #remoce the new line
print $s, "\n"; #see how i have to manually add "\n"

Hope that helps.
****************
::goOgler::
http://www.tinmith.net
Title: Re: why is the command "chomp" used in U
Post by: Addy on August 04, 2004, 04:37:06 AM
Quote
hi everybody,
can i know what is the use of @ inUNIX?

Did you mean: the use of '@' in shell-programming?
Here's what `info bash` says about it:
Quote
Expands to the positional parameters, starting from one.  When the expansion occurs within double quotes, each parameter expands to a separate word.  That is, `"$@"' is equivalent to `"$1" "$2" ...'.
When there are no positional parameters, `"$@"' and `$@' expand to nothing (i.e., they are removed).


The '@' also seperates the username from the hostname, e.g.: addy@MyComputer