Variable being stored with additional characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Variable being stored with additional characters
# 1  
Old 05-28-2013
Wrench Variable being stored with additional characters

I am trying to store a string value to a temporary variable within my script. When I run the command manually it returns the expected value, but from the script an additional "\r" is at the end.

Code:
tCurrentStatus=`cat ${tPC_status} | grep 'Current status' | awk '{print $NF}'`

output:
cat ${tPC_status} | grep 'Current status' | awk '{print $NF}'+ cat /home/jr/EOF/pc_monitor_EOF_status.out
+ grep 'Current status'
+ awk '{print $NF}'
+ tCurrentStatus=$'EOF\r'

Why does the "\r" appear in the script, but not manually?

Thanks in advance for any help.
# 2  
Old 05-28-2013
This:
Code:
tCurrentStatus=`cat ${tPC_status} | grep 'Current status' | awk '{print $NF}'`

my be wirtten like this
Code:
tCurrentStatus=$(awk '/Current status/ {print $NF}' ${tPC_status})

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

List of All Users Stored in Variable

I'm trying to get a list of all users on the system, store the list in a variable, then find all the files of a certain extension owned by each of the users. The command I use to get the list is getent passwd | cut -d: -f1 | sortand this works just fine. However, if I try to store it in a... (1 Reply)
Discussion started by: hobscrk777
1 Replies

2. Red Hat

How to check values stored in variable?

hey, i have stored values of query like this val_2=$( sqlplus -s rte/rted1@rel75d1 << EOF set heading off select source_id from cvt_istats where istat_id > $val_1; exit EOF ) echo $val_2 now , val_2 has five values displayed like this 1 2 3 4 5 what i have to do is to check the... (1 Reply)
Discussion started by: ramsavi
1 Replies

3. Shell Programming and Scripting

Display Additional Variable string in awk print command

Hi all, I have script to monitor and sum up the total memory use up for each individual process. proc=$1 svmon -P -O summary=basic,unit=MB|awk 'NR>4'|grep -w "${proc}" |awk '{sum+=$3} END {printf "\t" sum """\n";}' But I would like the script to be able to display as following ... (3 Replies)
Discussion started by: ckwan
3 Replies

4. Shell Programming and Scripting

Function returns a value but cannot be stored in other variable

I need help to store the value returned from the function to one variable and then use that variable. PREVIOUS_DATE_FUNCTION() { date '+%m %d %Y' | { read MONTH DAY YEAR DAY=`expr "$DAY" - 1` case "$DAY" in 0) MONTH=`expr "$MONTH" - 1` case... (1 Reply)
Discussion started by: aroragaurav.84
1 Replies

5. Shell Programming and Scripting

Variable not found error for a variable which is returned from stored procedure

can anyone please help me with this: i have written a shell script and a stored procedure which has one OUT parameter. now i want to use that out parameter as an input to the unix script but i am getting an error as variable not found. below are the unix scripts and stored procedure... ... (4 Replies)
Discussion started by: swap21783
4 Replies

6. Shell Programming and Scripting

Adding additional characters while preserving original text

Hi Forum. I'm struggling on this relatively easy request to add additional 4 0's to an existing text in a file (whenever I see the pattern -# where # represents any number) using sed command while preserving the rest of the text in the files. Original Text: $DBConnection_EDW=SAS2EDW... (5 Replies)
Discussion started by: pchang
5 Replies

7. Shell Programming and Scripting

How to define a variable with variable definition is stored in a variable?

Hi all, I have a variable say var1 (output from somewhere, which I can't change)which store something like this: echo $var1 name=fred age=25 address="123 abc" password=pass1234 how can I make the variable $name, $age, $address and $password contain the info? I mean do this in a... (1 Reply)
Discussion started by: freddy1228
1 Replies

8. Linux

Incrementing the date stored in the variable

Hi all, I have a variable with date as 20080831 . Now I want to increment it as 20080901 and so on.Is there any command for this. Please help me. thanks rameez (1 Reply)
Discussion started by: rameezrajas
1 Replies

9. Shell Programming and Scripting

Increment variable stored in a file

Hi, I want to write a perl script, which will increment number stored in file. I want to do this without any file handles. I think we have to use some UNIX commands. I am not sure how to do this with file handles. Thanks, (1 Reply)
Discussion started by: solitare123
1 Replies

10. UNIX for Dummies Questions & Answers

can i exectue a command stored in a variable.it goes like this

hi the code i ve written is as follows: command="egrep ',100,|,200,' | wc -l" count =`cat trial.txt | $command` echo "$count" the contents of trial.txt is : 000,100,200,300, 001,200,100,201, 002,200,100,400, i need to get the count using the command stored in a variable and using... (2 Replies)
Discussion started by: Syms
2 Replies
Login or Register to Ask a Question