TIMFOX123
asked on
bash Variables with hex 0a on the end
I am getting data in bash and storing it in Variables.
Half the time I get the string, the other half of the time I get the string terminated with hex 0a on the end if I
pipe it to hexedit -C
is there an easy way to strip this from the variable with a $(varname. ) or something like it ?
I am having this issue a lot
I am using the later version of redhat :)
Half the time I get the string, the other half of the time I get the string terminated with hex 0a on the end if I
pipe it to hexedit -C
is there an easy way to strip this from the variable with a $(varname. ) or something like it ?
I am having this issue a lot
I am using the later version of redhat :)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you both
example, If I:
grep root /etc/passwd | hexdump -C
you will see the line ends with a hex 0a
if you want to get rid of the hex 0a you can:
grep root /etc/passwd | tr -d '\n' | hexdump -C
There is a part of bash that I have used but to not understand where you can modify stuff with ${}
what I would like to do is to take a varable that has a hex 0a an the end and when I use it I can "chomp" it off
echo ${varname xxxxxx }
where the xxxx is code that I do not know.
also when I was saying about "later version of Linux" I was not being clear. I should have said "currently supported" Linux like 5,6,7.
thank you so much
example, If I:
grep root /etc/passwd | hexdump -C
you will see the line ends with a hex 0a
if you want to get rid of the hex 0a you can:
grep root /etc/passwd | tr -d '\n' | hexdump -C
There is a part of bash that I have used but to not understand where you can modify stuff with ${}
what I would like to do is to take a varable that has a hex 0a an the end and when I use it I can "chomp" it off
echo ${varname xxxxxx }
where the xxxx is code that I do not know.
also when I was saying about "later version of Linux" I was not being clear. I should have said "currently supported" Linux like 5,6,7.
thank you so much
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hex 0A is a newline (AKA line-feed) character, which is the standard UNIX/Linux line terminator.
Q1. Are you able to post your code so we can see how that's happening?
> "Half the time I get the string, the other half..."
Q2. When you say "half the time", do you mean in half of the variables, or do you get different results with different data, or what?
> "I am using the later version of redhat :)"
Q3. Later than what?