Without the aid of the escape mechanism, how to put a raw string into a variable?
Hi guys and gals...
I have been racking my brains with this one and I can't find anything about it...
Consider the code and the results below:
Results on OSX 10.14.x:
As you can see saving a rawstring to disk and retrieving it again works but trying to force a rawstring without the escape mechanism fails catastrophically.
This is one of the USEFUL uses of 'cat' as it works admirably in this case but it requires I/O to do so...
I need to avoid the use of the escape mechanism inside the failing condition in case I want to __edit__ said rawstring inside any code.
I would like to know what is different about putting a rawstring into a variable using 'cat' and attempting to do so using hard coding.
# The line below does not even get executed!
echo "${STRING}"
.
.
.
Of course not - it is part of the single quoted literal string started with the very last character two lines above.
I'm afraid you won't escape escaping in some way. Try e.g. using this mechanism man bash:
Quote:
Quoting:
Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences, if present, are decoded as follows: ...
I already know about conjoining strings and this is the way 'set' does it from the working part of the code:
But I did say I would like to be able to edit the STRING on the fly so what if I deleted say ' or " inside the STRING?
EDIT:
Just seen your edit and that looks like a good idea thanks I'll try it...
Last edited by wisecracker; 04-12-2020 at 08:42 AM..
Reason: See EDIT:
An embedded string in a shell script is normally fenced with either ' or " so you need to escape these characters inside the string.
Try a here doc:
Now the fence is a custom word.
You must quote it to prevent variable substitutions.
BTW if a file or a here doc has got one line then read is smarter than cat.
An embedded string in a shell script is normally fenced with either ' or " so you need to escape these characters inside the string.
Try a here doc:
Now the fence is a custom word.
You must quote it to prevent variable substitutions.
BTW if a file or a here doc has got one line then read is smarter than cat.
cat does not omit the space, (decimal character 32).
--- Post updated at 05:11 PM ---
Hi Rudic...
(HOPEFULLY THIS DOES NOT ATTACH TO THE PREVIOUS, if it does apologies...)
Thanked your previous post...
OSX 10.14.x, default bash terminal, calling dash inside the code...
Last edited by wisecracker; 04-12-2020 at 01:21 PM..
Debian 9 64x - LXDE
How can i disable escape sequences in a variable?
#!/bin/bash
#mainscript
. "./links.bash"
echo "$red_start This text should be red $color_end"#!/bin/bash
#links.bash
#colors
red_start="\eOutput that i get:
\e
Output expected:
This text should be... (5 Replies)
Hello,
Below script works fine when I manually enter required information for each file. When it comes to shell in auto mode, it gives various errors.
I am under ubuntu 14.04 / trusty.
manual_run.sh:
#!/bin/bash
/usr/bin/ffmpeg -start_at_zero -copyts -i nicki.mp4 -c:v mpeg2video \
-b:v 500k... (3 Replies)
Hi,
I am trying to read an Oracle listener log file line by line and need to separate the lines into several fields. The field delimiter for the line happens to be an asterisk.
I have the script below to start with but when running it, the echo command is globbing it to include other... (13 Replies)
How to store escape character in the variable.
Var=abc,def,ghi,jkl
echo ${Var} | sed -e "s/,/|\\\\./g;s/^/\\\\./g"
\.abc|\.def|\.ghi|\.hjk
Var1=`echo ${Var} | sed -e "s/,/|\\\./g;s/^/\\\./g"`
Actual:
-------
echo $Var1
.abc|.def|.ghi|.jkl
Expected:
---------
echo $Var1... (4 Replies)
I tried to parse data from switch configuration files
vlan 1727 name SQ5506-15 by port
tagged ethe 8/1 to 8/2
untagged ethe 1/13
!
vlan 2105 name SQ5620-7007(BR2) by port
tagged ethe 8/1 to 8/2
untagged ethe 1/17
!
interface ethernet 1/13
port-name SQ5506-15.nic0
rate-limit... (2 Replies)
I want it to ouput "abcd", but it dosen't.
1 #include<stdio.h>
2 int main()
3 {
4 printf("a\x62cd");
5 }
6
gcc alarm.c -o alarm
alarm.c: In function 'main':
alarm.c:4:9: warning: hex escape sequence out of range
It seems that the complier joint "cd" as part of... (8 Replies)
Hello all,
I have a string var which contains formatting characters at the end, it is a string with EScape sequences at the end of it.
How can I remove them so that I only keep the 'real' text?
I tried :
var1=${var1%%\033[0m}
does not seem to do the job ....
Please help
Thanks (2 Replies)
Dear all,
I want below data to make it in column format.so i will see the data like this
cdrID teleServiceCode chargedPartyNumber ... ... ... ...
"egmailcom0w10ggzx00" 'sMS (5)' "716323770"
"m17ifi5z30w0z6o7200" 'sMS (5)' ... (7 Replies)