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
Shell Implementation not working correctly AirBronto High Level Programming 14 02-15-2008 10:41 PM
if not working correctly 2dumb Shell Programming and Scripting 3 05-03-2007 03:38 PM
assign value to variable is not working agustincm Shell Programming and Scripting 3 10-13-2006 04:07 AM
Variable with $ do not show correctly insania Shell Programming and Scripting 3 07-02-2006 12:24 AM
Script not working correctly elchalateco UNIX for Dummies Questions & Answers 2 10-11-2002 05: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 05-30-2007
walsh_j walsh_j is offline
Registered User
  
 

Join Date: May 2007
Posts: 3
Variable not working correctly.

Hi,

I have a script where I am trying to set a local variable using the following,

MYVAR="$NAME"_"$NAME2".txt

where say,

NAME = one
NAME2 = two

so I want the output one_two.txt but what I am getting is,

two.txt

basically the $NAME2 is overwriting, what am I doing wrong?

Thanks,
  #2 (permalink)  
Old 05-30-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,429
Works fine with bash.

Code:
$ NAME=one
$ NAME2=two
$ MYVAR="$NAME"_"$NAME2".txt
$ echo $MYVAR
one_two.txt
$

You can try the following syntax:

Code:
$ MYVAR="${NAME}_${NAME2}.txt"
$ echo $MYVAR
one_two.txt
$

Jean-Pierre.
  #3 (permalink)  
Old 05-30-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Try

MYVAR="${NAME}_${NAME2}".txt
  #4 (permalink)  
Old 05-30-2007
coreysan coreysan is offline
Registered User
  
 

Join Date: May 2007
Posts: 7
Variable not working correctly

On my unix box everytime I use the underbar character "_" I run into trouble
when using it to concatenate two names. The OS reads in the underbar and
looks to the next character, handling it differently.

On one of your replies, someone demonstrated correctly that when you
concatenate, keep the other names plus the underbar character all within
double quotes. That way, the OS will treat the underbar as a literal character instead of (probably) a meta-character.
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 05:58 PM.


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