The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
variable not retaining value gillbates Shell Programming and Scripting 5 11-16-2005 06:16 PM
Length of a variable karyn1617 Shell Programming and Scripting 3 02-08-2005 06:41 PM
Parsing a variable length record Barb UNIX for Dummies Questions & Answers 17 10-01-2004 09:37 AM
length of data greater than 11 thanuman UNIX for Dummies Questions & Answers 2 09-10-2004 08:13 AM
creating a fixed length output from a variable length input r1500 Shell Programming and Scripting 2 12-03-2003 01:09 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-22-2002
app4dxh
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Parsing data and retaining the full length of variable

Here's is an example of what I want to do:

var1="Horse "
var2="Cat "
var3="Fish "

for animals in "$var1" "$var2" "$var3"
do
set $animals
pet=$1
## Ok, now I want to get the values of $pet, but
## I want to retain the full length it was originally in
## var1, var2 or var3, say it was 10 bytes. If I then do
## the following:
echo "$pet : "
The printing of this(the colons in this example) will not line up:
Horse :
Cat :
Fish :

I think I have done this before, but it is Friday and my brain is fried.....any help would make my weekend!

Thanks
  #2 (permalink)  
Old 11-22-2002
Vishnu Vishnu is offline
Registered User
  
 

Join Date: Aug 2002
Location: Marlboro, MA
Posts: 114
you need to double quote all those variables carrying animals including the positional parameter $1...

try this...
Code:
    var1="Horse     " 
    var2="Cat       " 
    var3="Fish      " 

    for animals in "$var1" "$var2" "$var3"
    do
       set "$animals"
       pet="$1"
       echo "$pet :"
    done
Cheers!
Vishnu.
  #3 (permalink)  
Old 11-22-2002
app4dxh
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Talking

"Thanks"
  #4 (permalink)  
Old 11-22-2002
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Also, see if you have the printf command... it's internal in some shells, and can be found as a standalone binary on some systems. You can specify field width...
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:37 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0