Inconsistent variable assignment issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Inconsistent variable assignment issue
# 1  
Old 12-14-2009
Inconsistent variable assignment issue

I am using a piece of code which is working fine in some cases and is not working in some other instances. All I am doing is grep'ing and concatenating.

Below is a working scenario.

Code:
$ echo $var1
REPLYFILENAME=Options_NSE1.txt.enc
 
$ FILE_NM=`echo ${var1##*=}`.gz (Take everything after symbol = from var1 and append .gz)

$ echo $FILE_NM
Options_NSE1.txt.enc.gz

$ echo "File to be ftped is $FILE_NM"
File to be ftped is Options_NSE1.txt.enc.gz

The same code is not working when I have a different value for var1.

Code:
$ echo $var1
REPLYFILENAME=Options_UK1.txt.enc

$ FILE_NM=`echo ${var1##*=}`.gz (Take everything after symbol = from var1 and append .gz)

$ echo $FILE_NM
.gzions_UK1.txt.enc (Incorrectly prints the variable $FILE_NM)

$ echo "File to be ftped is $FILE_NM"
.gze to be ftped is Options_UK1.txt.enc (Puts some garbage .gze in place of the word "File". Prints $FILE_NM correctly, which is different from the o/p of the previous command)

Looks like the echo command is replacing the first 3 characters of what ever it is printing with .gz.Not sure why.

Any help with the above issue is highly appreciated.



Last edited by pludi; 12-14-2009 at 04:15 PM.. Reason: code tags, please...
# 2  
Old 12-14-2009
Where does the value of var1 come from? Because at a first glance, it looks like there's a carriage return in there when it shouldn't be. If the utility is available, could you post the output of
Code:
echo $var1 | xxd

or
Code:
echo $var1 | hexdump -C

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable Assignment

Hi I am facing a problem. export local_folder=/opt/app/ cd /opt/app/abc/ abcversion="abc*" (abcga5 is inside /opt/app/abc/) echo $abcversion (it echoes the correct version as abcga5 ) Now when I reuse the value of abcversion for a below path: export... (6 Replies)
Discussion started by: ankur328
6 Replies

2. Shell Programming and Scripting

Same Variable Assignment

Hi I have a strange problem: In my shell script I am performing a copy task: . prop.txt cp -r $dir/ $dir/archive $dir is fetched from a property file (prop.txt) which stores its value dir=/opt/data Now the problem is another dir1 comes into picture. I only want to add... (1 Reply)
Discussion started by: ankur328
1 Replies

3. Shell Programming and Scripting

Usage of # in assignment of variable

guys, i would like to know what does the below does. tr=`echo $bfile | cut -d"." -f4` tr=${tr#TR} i tried with assigning a value and executed second line. but after that also value of tr remains same. thanks in advance .. (1 Reply)
Discussion started by: expert
1 Replies

4. Shell Programming and Scripting

Mutilple variable assignment

i have file that contains data as follows 1 2 3 now i need to assign them into three variables a1=1 a2=2 a3=3 Everything should come under a loop. In reality i may have 10 values which has to be assigned to 10 variable. if i have 25 values ( lines) , each should be assigned into... (3 Replies)
Discussion started by: Rajesh_us
3 Replies

5. Shell Programming and Scripting

issue with nawk while using variable assignment

#ifconfig -a | nawk '/1.1.1.1/{print}' inet 1.1.1.1 netmask xxxxxxxxx broadcast 0.0.0.0 If i assign the ip to a variable and search for the variable nothing gets printed!! # ifconfig -a | nawk -v ip=1.1.1.1 '/ip/{print}' I am not able to understand why this is happening! (6 Replies)
Discussion started by: chidori
6 Replies

6. Shell Programming and Scripting

AWK Variable assignment issue Ksh script

Hi There, I am writing a ksh script which assigns variable values from file "A" and passes that variables to file "B". While passing the parameters an additional "$" sign is being assigned to awk -v option. Could any one help me with this please. #!/bin/ksh head -1... (3 Replies)
Discussion started by: Jeevanm
3 Replies

7. Shell Programming and Scripting

Help with variable assignment

Hi, In AIX I have a variable with , (coma) separated values assigned to it like shown below var1=apple,boy,chris i want to convert this to var1='apple','boy','chris' the number of values assigned to var1 might change and it could be from 1 to n any suggestions please? (3 Replies)
Discussion started by: rahul9909
3 Replies

8. Shell Programming and Scripting

Dynamic variable assignment

Hi all, I’m very new to UNIX programming. I have a question on dynamic variable 1. I’m having delimited file (only one row). First of all, I want to count number of columns based on delimiter. Then I want to create number of variables equal to number of fields. Say number of... (5 Replies)
Discussion started by: mkarthykeyan
5 Replies

9. Shell Programming and Scripting

substituted variable assignment

I try to run this script, however, it gives an exception in line 3. How do I do an assignment to a substituted variable? #!/bin/bash name=fruit ext_$(eval echo ${name})=apple tmp=ext_$(eval echo ${name}) if ]; then echo "apple" elif ]; then echo "orange" fi echo ${!tmp} Error... (2 Replies)
Discussion started by: angelokh
2 Replies

10. UNIX for Dummies Questions & Answers

@ in a variable assignment

Hello Everybody, Does anyone know what the @ symbol means in a csh script, if used with a variable assignment as below @ line = 1 why not just use.... set line=1 Many thanks rkap (1 Reply)
Discussion started by: rkap
1 Replies
Login or Register to Ask a Question