Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace null char in variable

Status
Not open for further replies.

mrn

MIS
Apr 27, 2001
3,993
GB
How can I replace a null value within a variable?

I know the var has a value set using

Code:
if [ -z $ver ] ; then

 if [ $(ver+EMPTY} = EMPTY] ; then
  echo "var empty"
 else
  echo "var not set"
 fi
else
 echo "var has value"
fi


but if I echo $ver > file

the file appears empty.

Ideas?

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
Code:
: ${ver:=Default}

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV, but it's not empty so ver always has a value even if you can't see it.

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
I already said in my original post I know the var has a value.






Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
if test "${VER}COFFEE" = "COFFEE"
then
VER="SOMETHINGELSE"
fi
 
Also, if you echo $ver out to a file, do a cat -v on that file, that might give you some insight as to what this hidden value might be, and therefore you might be able to strip it with tr -d.

Bet you a wooden nickel it's a carriage return =)
 
What are the result of the following commands ?
echo "$ver" | od
echo "$ver" > file && ls -l file
echo $ver > file && ls -l file

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for you help on this guys,

I've found the problem, as in most cases, it was the keyboard / chair interface.

Thanks for your time.

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top